From 06fad4dc321702bc574698dd7031abe7f800034f Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Mon, 12 Aug 2013 17:28:12 +0200 Subject: [PATCH] SONAR-4563 Use strict comparison for createdAfter in the Issues search engine --- .../notification/NewIssuesEmailTemplate.java | 2 +- .../resources/org/sonar/l10n/core.properties | 3 +-- .../unresolved_issues_per_assignee.html.erb | 2 +- .../NewIssuesEmailTemplateTest.java | 2 +- .../org/sonar/core/issue/db/IssueMapper.xml | 4 ++-- .../org/sonar/core/issue/db/IssueDaoTest.java | 21 ++++++++++++++++--- .../should_select_by_date_creation.xml | 2 +- .../java/org/sonar/api/issue/IssueQuery.java | 14 ++++++------- .../org/sonar/api/issue/RubyIssueService.java | 2 +- .../server/issue/IssueFilterParameters.java | 4 ++-- .../server/issue/PublicRubyIssueService.java | 2 +- .../widgets/issues/_issues_list.html.erb | 2 +- 12 files changed, 37 insertions(+), 23 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/NewIssuesEmailTemplate.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/NewIssuesEmailTemplate.java index fd3fc36711f..0f10dcfa198 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/NewIssuesEmailTemplate.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/NewIssuesEmailTemplate.java @@ -68,7 +68,7 @@ public class NewIssuesEmailTemplate extends EmailTemplate { String dateString = notification.getFieldValue("projectDate"); if (projectKey != null && dateString != null) { Date date = DateUtils.parseDateTime(dateString); - String url = String.format("%s/issues/search?componentRoots=%s&createdAtOrAfter=%s", + String url = String.format("%s/issues/search?componentRoots=%s&createdAt=%s", settings.getServerBaseURL(), encode(projectKey), encode(DateUtils.formatDateTime(date))); sb.append("\n").append("See it in SonarQube: ").append(url).append("\n"); } diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties index 1ee078c3dd9..b5a59686365 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -556,7 +556,7 @@ issue_filter.are_you_sure_want_delete_filter_x=Are you sure that you want to del issue_filter.private=Private issue_filter.shared_with_all_users=Shared with all users issue_filter.sharing=Sharing - +issue_filter.no_issues=No issues #------------------------------------------------------------------------------ # @@ -1039,7 +1039,6 @@ widget.hotspot_most_violated_resources.property.numberOfLines.name=Number of lin widget.my_reviews.name=My Unresolved Issues widget.my_reviews.description=Shows unresolved issues assigned to the current user. -widget.my_reviews.no_issue=No issue. widget.my_reviews.property.numberOfLines.name=Number of lines widget.my_reviews.property.numberOfLines.desc=Maximum number of issues displayed at the same time. diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/issues/unresolved_issues_per_assignee.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/issues/unresolved_issues_per_assignee.html.erb index 46662763c63..08ba140c521 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/issues/unresolved_issues_per_assignee.html.erb +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/issues/unresolved_issues_per_assignee.html.erb @@ -35,7 +35,7 @@

<%= message('widget.reviews_per_developer.name') -%>

<% if assignees.size ==0 %> - <%= message('widget.reviews_per_developer.name') -%> + <%= message('issue_filter.no_issues') -%> <% else %>
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/notification/NewIssuesEmailTemplateTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/notification/NewIssuesEmailTemplateTest.java index 97f57cdf8d5..7edf14c4000 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/notification/NewIssuesEmailTemplateTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/notification/NewIssuesEmailTemplateTest.java @@ -73,7 +73,7 @@ public class NewIssuesEmailTemplateTest { "Project: Struts\n" + "32 new issues\n" + "\n" + - "See it in SonarQube: http://nemo.sonarsource.org/issues/search?componentRoots=org.apache%3Astruts&createdAtOrAfter=2010-05-18T16%3A50%3A45%2B0200\n"); + "See it in SonarQube: http://nemo.sonarsource.org/issues/search?componentRoots=org.apache%3Astruts&createdAt=2010-05-18T16%3A50%3A45%2B0200\n"); } @Test diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml index e2c55b4aa92..2aca03357aa 100644 --- a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml @@ -290,8 +290,8 @@ and i.issue_creation_date > #{query.createdAfter} - - and i.issue_creation_date >= #{query.createdAtOrAfter} + + and i.issue_creation_date = #{query.createdAt} and i.issue_creation_date < #{query.createdBefore} diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java index b8fdb2977bc..10416af7435 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java @@ -120,16 +120,31 @@ public class IssueDaoTest extends AbstractDaoTestCase { public void should_select_by_date_creation() { setupData("shared", "should_select_by_date_creation"); + // created after, strictly IssueQuery query = IssueQuery.builder().createdAfter(DateUtils.parseDate("2013-04-15")).build(); assertThat(dao.selectIssueIds(query)).hasSize(1); assertThat(dao.selectIssueIds(query).get(0).getId()).isEqualTo(100L); - query = IssueQuery.builder().createdAtOrAfter(DateUtils.parseDate("2013-04-15")).build(); + query = IssueQuery.builder().createdAfter(DateUtils.parseDate("2022-01-01")).build(); + assertThat(dao.selectIssueIds(query)).isEmpty(); + + + // created at a given date + query = IssueQuery.builder().createdAt(DateUtils.parseDate("2013-04-16")).build(); assertThat(dao.selectIssueIds(query)).hasSize(1); assertThat(dao.selectIssueIds(query).get(0).getId()).isEqualTo(100L); - query = IssueQuery.builder().createdBefore(DateUtils.parseDate("2013-04-17")).requiredRole("user").build(); - assertThat(dao.selectIssueIds(query)).hasSize(2); + query = IssueQuery.builder().createdAt(DateUtils.parseDate("2010-01-01")).build(); + assertThat(dao.selectIssueIds(query)).isEmpty(); + + + // created before + query = IssueQuery.builder().createdBefore(DateUtils.parseDate("2013-04-14")).build(); + assertThat(dao.selectIssueIds(query)).hasSize(1); + assertThat(dao.selectIssueIds(query).get(0).getId()).isEqualTo(101L); + + query = IssueQuery.builder().createdBefore(DateUtils.parseDate("2010-01-01")).build(); + assertThat(dao.selectIssueIds(query)).isEmpty(); } @Test diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_date_creation.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_date_creation.xml index cf6048a5e83..cd509c70d50 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_date_creation.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_date_creation.xml @@ -18,7 +18,7 @@ assignee="perceval" author_login="[null]" issue_attributes="JIRA=FOO-1234" - issue_creation_date="2013-04-16 15:50:45" + issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" created_at="2013-04-16" diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java index d7ce899c4f8..9826894fc23 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java @@ -70,7 +70,7 @@ public class IssueQuery { private final Boolean assigned; private final Boolean planned; private final Boolean resolved; - private final Date createdAtOrAfter; + private final Date createdAt; private final Date createdAfter; private final Date createdBefore; private final String sort; @@ -97,7 +97,7 @@ public class IssueQuery { this.assigned = builder.assigned; this.planned = builder.planned; this.resolved = builder.resolved; - this.createdAtOrAfter = builder.createdAtOrAfter; + this.createdAt = builder.createdAt; this.createdAfter = builder.createdAfter; this.createdBefore = builder.createdBefore; this.sort = builder.sort; @@ -168,8 +168,8 @@ public class IssueQuery { } @CheckForNull - public Date createdAtOrAfter() { - return (createdAtOrAfter == null ? null : new Date(createdAtOrAfter.getTime())); + public Date createdAt() { + return (createdAt == null ? null : new Date(createdAt.getTime())); } @CheckForNull @@ -226,7 +226,7 @@ public class IssueQuery { private Boolean assigned = null; private Boolean planned = null; private Boolean resolved = null; - private Date createdAtOrAfter; + private Date createdAt; private Date createdAfter; private Date createdBefore; private String sort; @@ -315,8 +315,8 @@ public class IssueQuery { return this; } - public Builder createdAtOrAfter(@Nullable Date d) { - this.createdAtOrAfter = (d == null ? null : new Date(d.getTime())); + public Builder createdAt(@Nullable Date d) { + this.createdAt = (d == null ? null : new Date(d.getTime())); return this; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/RubyIssueService.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/RubyIssueService.java index 1afd5e480ee..26bea532feb 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/RubyIssueService.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/RubyIssueService.java @@ -65,7 +65,7 @@ public interface RubyIssueService extends ServerComponent { *
  • 'assigned': true to get only assigned issues, false to get only unassigned issues. By default no filtering is done.
  • *
  • 'createdAfter': match all the issues created after the given date (strictly). * Both date and datetime ISO formats are supported: 2013-05-18 or 2010-05-18T15:50:45+0100
  • - *
  • 'createdAtOrAfter': match all the issues created after the given date (inclusive). + *
  • 'createdAt': match all the issues created at the given date (require second precision). * Both date and datetime ISO formats are supported: 2013-05-18 or 2010-05-18T15:50:45+0100
  • *
  • 'createdBefore': match all the issues created before the given date (exclusive). * Both date and datetime ISO formats are supported: 2013-05-18 or 2010-05-18T15:50:45+0100
  • diff --git a/sonar-server/src/main/java/org/sonar/server/issue/IssueFilterParameters.java b/sonar-server/src/main/java/org/sonar/server/issue/IssueFilterParameters.java index d1101062bf5..12ec6819dad 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/IssueFilterParameters.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/IssueFilterParameters.java @@ -47,7 +47,7 @@ public class IssueFilterParameters { public static final String ASSIGNED = "assigned"; public static final String PLANNED = "planned"; public static final String CREATED_AFTER = "createdAfter"; - public static final String CREATED_AT_OR_AFTER = "createdAtOrAfter"; + public static final String CREATED_AT = "createdAt"; public static final String CREATED_BEFORE = "createdBefore"; public static final String PAGE_SIZE = "pageSize"; public static final String PAGE_INDEX = "pageIndex"; @@ -55,7 +55,7 @@ public class IssueFilterParameters { public static final String ASC = "asc"; public static final List ALL = ImmutableList.of(ISSUES, SEVERITIES, STATUSES, RESOLUTIONS, RESOLVED, COMPONENTS, COMPONENT_ROOTS, RULES, ACTION_PLANS, REPORTERS, - ASSIGNEES, ASSIGNED, PLANNED, CREATED_AFTER, CREATED_BEFORE, PAGE_SIZE, PAGE_INDEX, SORT, ASC); + ASSIGNEES, ASSIGNED, PLANNED, CREATED_AT, CREATED_AFTER, CREATED_BEFORE, PAGE_SIZE, PAGE_INDEX, SORT, ASC); public static final List ALL_WITHOUT_PAGINATION = newArrayList(Iterables.filter(ALL, new Predicate() { @Override diff --git a/sonar-server/src/main/java/org/sonar/server/issue/PublicRubyIssueService.java b/sonar-server/src/main/java/org/sonar/server/issue/PublicRubyIssueService.java index 9f39ad2c2fe..768ac484879 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/PublicRubyIssueService.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/PublicRubyIssueService.java @@ -88,7 +88,7 @@ public class PublicRubyIssueService implements RubyIssueService { .assignees(RubyUtils.toStrings(props.get(IssueFilterParameters.ASSIGNEES))) .assigned(RubyUtils.toBoolean(props.get(IssueFilterParameters.ASSIGNED))) .planned(RubyUtils.toBoolean(props.get(IssueFilterParameters.PLANNED))) - .createdAtOrAfter(RubyUtils.toDate(props.get(IssueFilterParameters.CREATED_AT_OR_AFTER))) + .createdAt(RubyUtils.toDate(props.get(IssueFilterParameters.CREATED_AT))) .createdAfter(RubyUtils.toDate(props.get(IssueFilterParameters.CREATED_AFTER))) .createdBefore(RubyUtils.toDate(props.get(IssueFilterParameters.CREATED_BEFORE))) .pageSize(RubyUtils.toInteger(props.get(IssueFilterParameters.PAGE_SIZE))) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/project/widgets/issues/_issues_list.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/project/widgets/issues/_issues_list.html.erb index feb14531f34..f061f92f74b 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/project/widgets/issues/_issues_list.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/project/widgets/issues/_issues_list.html.erb @@ -23,7 +23,7 @@ %> <% if paging.total() == 0 %> - <%= message('widget.my_reviews.no_issue') -%> + <%= message('issue_filter.no_issues') -%> <% else %> -- 2.39.5