]> source.dussan.org Git - sonarqube.git/commitdiff
Revert "SONAR-5967 Instead of not displaying anymore the source files containing...
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 23 Dec 2014 14:10:30 +0000 (15:10 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 23 Dec 2014 14:15:01 +0000 (15:15 +0100)
server/sonar-server/src/main/java/org/sonar/server/source/SourceService.java
server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineIndex.java
server/sonar-server/src/main/java/org/sonar/server/source/ws/ShowAction.java
server/sonar-server/src/test/java/org/sonar/server/source/SourceServiceTest.java
server/sonar-server/src/test/java/org/sonar/server/source/index/SourceLineIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/source/ws/ShowActionTest.java

index b65ebd9805016972208ac75cd91601d967fa00c3..4b4add00ce50268c9dc2ac05575bdc65a2107642 100644 (file)
@@ -77,10 +77,6 @@ public class SourceService implements ServerComponent {
     return lines;
   }
 
-  public long countLines(String fileUuid){
-    return sourceLineIndex.countLines(fileUuid);
-  }
-
   @CheckForNull
   public String getScmAuthorData(String fileKey) {
     checkPermission(fileKey);
index 4567a0f11bab592d753e60fdcdc63830150b4e2a..f3c84bb650ca9b1b8c5c6f477a4b96a411e8085b 100644 (file)
@@ -74,12 +74,4 @@ public class SourceLineIndex implements ServerComponent {
 
     return lines;
   }
-
-  public long countLines(String fileUuid) {
-    return esClient.prepareCount(SourceLineIndexDefinition.INDEX)
-      .setTypes(SourceLineIndexDefinition.TYPE)
-      .setQuery(QueryBuilders.boolQuery()
-        .must(QueryBuilders.termQuery(SourceLineIndexDefinition.FIELD_FILE_UUID, fileUuid)))
-      .get().getCount();
-  }
 }
index 3ba39a9016916f3c5ba8d88c171ce153f5bdaf06..8458630bd5cb3b0751f3a5afd1ccf739e0ad4463 100644 (file)
@@ -78,6 +78,7 @@ public class ShowAction implements RequestHandler {
   @Override
   public void handle(Request request, Response response) {
     String fileKey = request.mandatoryParam("key");
+    UserSession.get().checkComponentPermission(UserRole.CODEVIEWER, fileKey);
 
     int from = Math.max(request.mandatoryParamAsInt("from"), 1);
     int to = (Integer) ObjectUtils.defaultIfNull(request.paramAsInt("to"), Integer.MAX_VALUE);
@@ -85,18 +86,7 @@ public class ShowAction implements RequestHandler {
     DbSession session = dbClient.openSession(false);
     try {
       ComponentDto componentDto = dbClient.componentDao().getByKey(session, fileKey);
-      UserSession.get().checkComponentPermission(UserRole.CODEVIEWER, fileKey);
-
-      long linesSize = sourceService.countLines(componentDto.uuid());
-      int size = to - from;
-      boolean disableHighlighting = size > 3000 && linesSize > 3000 ;
-
-      List<String> linesHtml;
-      if (!disableHighlighting) {
-        linesHtml = sourceService.getLinesAsHtml(componentDto.uuid(), from, to);
-      } else {
-        linesHtml = sourceService.getLinesAsTxt(componentDto.uuid(), from, to);
-      }
+      List<String> linesHtml = sourceService.getLinesAsHtml(componentDto.uuid(), from, to);
       JsonWriter json = response.newJsonWriter().beginObject();
       writeSource(linesHtml, from, json);
 
@@ -104,6 +94,7 @@ public class ShowAction implements RequestHandler {
     } finally {
       session.close();
     }
+
   }
 
   private void writeSource(List<String> lines, int from, JsonWriter json) {
index b7f5c2e58dc7392971fb2a6031bd25367d46639c..aac22010b27afe096ad3ce0aa6c0f60cc0588943 100644 (file)
@@ -43,7 +43,10 @@ import static org.fest.assertions.Assertions.assertThat;
 import static org.fest.assertions.Fail.fail;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
 
 @RunWith(MockitoJUnitRunner.class)
 public class SourceServiceTest {
@@ -149,9 +152,4 @@ public class SourceServiceTest {
     assertThat(result).contains("line1", "line2");
   }
 
-  @Test
-  public void count_lines() throws Exception {
-    service.countLines(COMPONENT_UUID);
-    verify(sourceLineIndex).countLines(COMPONENT_UUID);
-  }
 }
index 8f1873dba9ac4c0e47f631d5e57199923c45b240..ced283fc0bbce91febaa324095014b87c1b7b03d 100644 (file)
@@ -63,17 +63,4 @@ public class SourceLineIndexTest {
   public void should_reject_to_less_than_from() {
     index.getLines("polop", 2, 1);
   }
-
-  @Test
-  public void count_lines() throws Exception {
-    es.putDocuments(SourceLineIndexDefinition.INDEX, SourceLineIndexDefinition.TYPE,
-      this.getClass(),
-      "file1_line1.json",
-      "file1_line2.json",
-      "file2_line1.json",
-      "file2_line2.json",
-      "file2_line3.json");
-    assertThat(index.countLines("file1")).isEqualTo(2);
-    assertThat(index.countLines("file2")).isEqualTo(3);
-  }
 }
index 666d41691c5c4d20153067837c01ca76c305881d..c3471efa0bb89dfec79d54476513c6860857df0b 100644 (file)
@@ -38,7 +38,9 @@ import org.sonar.server.ws.WsTester;
 import static com.google.common.collect.Lists.newArrayList;
 import static org.mockito.Matchers.anyInt;
 import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 @RunWith(MockitoJUnitRunner.class)
 public class ShowActionTest {
@@ -74,7 +76,6 @@ public class ShowActionTest {
     String fileKey = "src/Foo.java";
     MockUserSession.set().addComponentPermission(UserRole.CODEVIEWER, "polop", fileKey);
     when(componentDao.getByKey(session, fileKey)).thenReturn(file);
-    when(sourceService.countLines(file.uuid())).thenReturn(6L);
     when(sourceService.getLinesAsHtml(eq(file.uuid()), anyInt(), anyInt())).thenReturn(newArrayList(
       "/*",
       " * Header",
@@ -93,7 +94,6 @@ public class ShowActionTest {
     String fileKey = "src/Foo.java";
     MockUserSession.set().addComponentPermission(UserRole.CODEVIEWER, "polop", fileKey);
     when(componentDao.getByKey(session, fileKey)).thenReturn(file);
-    when(sourceService.countLines(file.uuid())).thenReturn(6L);
     when(sourceService.getLinesAsHtml(file.uuid(), 3, 5)).thenReturn(newArrayList(
       " */",
       "",
@@ -112,7 +112,6 @@ public class ShowActionTest {
     String fileKey = "src/Foo.java";
     MockUserSession.set().addComponentPermission(UserRole.CODEVIEWER, "polop", fileKey);
     when(componentDao.getByKey(session, fileKey)).thenReturn(file);
-    when(sourceService.countLines(file.uuid())).thenReturn(6L);
     when(sourceService.getLinesAsHtml(file.uuid(), 1, 5)).thenReturn(newArrayList(
       " */",
       "",
@@ -127,72 +126,6 @@ public class ShowActionTest {
     verify(sourceService).getLinesAsHtml(file.uuid(), 1, 5);
   }
 
-  @Test
-  public void disable_highlighting_when_lines_greater_than_3000_without_from_and_to_params() throws Exception {
-    String fileKey = "src/Foo.java";
-    MockUserSession.set().addComponentPermission(UserRole.CODEVIEWER, "polop", fileKey);
-    when(componentDao.getByKey(session, fileKey)).thenReturn(file);
-    when(sourceService.countLines(file.uuid())).thenReturn(5000L);
-    WsTester.TestRequest request = tester
-      .newGetRequest("api/sources", "show")
-      .setParam("key", fileKey);
-    request.execute();
-
-    verify(sourceService).getLinesAsTxt(eq(file.uuid()), anyInt(), anyInt());
-    verify(sourceService, never()).getLinesAsHtml(eq(file.uuid()), anyInt(), anyInt());
-  }
-
-  @Test
-  public void disable_highlighting_when_lines_greater_than_3000_with_from_and_to_params() throws Exception {
-    String fileKey = "src/Foo.java";
-    MockUserSession.set().addComponentPermission(UserRole.CODEVIEWER, "polop", fileKey);
-    when(componentDao.getByKey(session, fileKey)).thenReturn(file);
-    when(sourceService.countLines(file.uuid())).thenReturn(5000L);
-    WsTester.TestRequest request = tester
-      .newGetRequest("api/sources", "show")
-      .setParam("key", fileKey)
-      .setParam("from", "1000")
-      .setParam("to", "5000");
-    request.execute();
-
-    verify(sourceService).getLinesAsTxt(eq(file.uuid()), anyInt(), anyInt());
-    verify(sourceService, never()).getLinesAsHtml(eq(file.uuid()), anyInt(), anyInt());
-  }
-
-  @Test
-  public void not_disable_highlighting_when_lines_smaller_than_3000_but_to_minus_to_greater_than_3000() throws Exception {
-    String fileKey = "src/Foo.java";
-    MockUserSession.set().addComponentPermission(UserRole.CODEVIEWER, "polop", fileKey);
-    when(componentDao.getByKey(session, fileKey)).thenReturn(file);
-    when(sourceService.countLines(file.uuid())).thenReturn(1000L);
-    WsTester.TestRequest request = tester
-      .newGetRequest("api/sources", "show")
-      .setParam("key", fileKey)
-      .setParam("from", "1000")
-      .setParam("to", "5000");
-    request.execute();
-
-    verify(sourceService, never()).getLinesAsTxt(eq(file.uuid()), anyInt(), anyInt());
-    verify(sourceService).getLinesAsHtml(eq(file.uuid()), anyInt(), anyInt());
-  }
-
-  @Test
-  public void not_disable_highlighting_when_lines_greater_than_3000_but_to_minus_to_smaller_than_3000() throws Exception {
-    String fileKey = "src/Foo.java";
-    MockUserSession.set().addComponentPermission(UserRole.CODEVIEWER, "polop", fileKey);
-    when(componentDao.getByKey(session, fileKey)).thenReturn(file);
-    when(sourceService.countLines(file.uuid())).thenReturn(5000L);
-    WsTester.TestRequest request = tester
-      .newGetRequest("api/sources", "show")
-      .setParam("key", fileKey)
-      .setParam("from", "1")
-      .setParam("to", "10");
-    request.execute();
-
-    verify(sourceService, never()).getLinesAsTxt(eq(file.uuid()), anyInt(), anyInt());
-    verify(sourceService).getLinesAsHtml(eq(file.uuid()), anyInt(), anyInt());
-  }
-
   @Test(expected = ForbiddenException.class)
   public void require_code_viewer() throws Exception {
     String fileKey = "src/Foo.java";