]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8931 simpler paging in selectOrganizationsWithoutLoadedTemplate
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 14 Mar 2017 13:46:03 +0000 (14:46 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 23 Mar 2017 16:38:34 +0000 (17:38 +0100)
server/sonar-db-dao/src/main/java/org/sonar/db/Pagination.java [new file with mode: 0644]
server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/PaginationTest.java [new file with mode: 0644]
server/sonar-db-dao/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java

diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/Pagination.java b/server/sonar-db-dao/src/main/java/org/sonar/db/Pagination.java
new file mode 100644 (file)
index 0000000..b3b76a6
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.db;
+
+import javax.annotation.concurrent.Immutable;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+@Immutable
+public final class Pagination {
+  private static final Pagination ALL = new Builder(1).andSize(Integer.MAX_VALUE);
+
+  private final int page;
+  private final int pageSize;
+
+  private Pagination(Builder builder) {
+    this.page = builder.page;
+    this.pageSize = builder.pageSize;
+  }
+
+  public static Pagination all() {
+    return ALL;
+  }
+
+  public static Builder forPage(int page) {
+    return new Builder(page);
+  }
+
+  public int getPage() {
+    return page;
+  }
+
+  public int getPageSize() {
+    return pageSize;
+  }
+
+  public int getOffset() {
+    return (page - 1) * pageSize;
+  }
+
+  public int getStartRowNumber() {
+    return getOffset() + 1;
+  }
+
+  public int getEndRowNumber() {
+    return page * pageSize;
+  }
+
+  public static final class Builder {
+    private final int page;
+    private int pageSize = 0;
+
+    public Builder(int page) {
+      checkArgument(page >= 1, "page index must be >= 1");
+      this.page = page;
+    }
+
+    public Pagination andSize(int pageSize) {
+      checkArgument(pageSize >= 1, "page size must be >= 1");
+      this.pageSize = pageSize;
+      return new Pagination(this);
+    }
+  }
+}
index a2a7bc9543b5903d1c53b8d80754190282650543..51d9d283b460a6ff36ae83a6bd5084c5b82ed685 100644 (file)
@@ -26,8 +26,8 @@ import java.util.Set;
 import org.sonar.api.utils.System2;
 import org.sonar.db.Dao;
 import org.sonar.db.DbSession;
+import org.sonar.db.Pagination;
 
-import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Objects.requireNonNull;
 import static org.sonar.db.DatabaseUtils.executeLargeInputs;
 
@@ -73,11 +73,8 @@ public class OrganizationDao implements Dao {
     return getMapper(dbSession).selectByPermission(userId, permission);
   }
 
-  public List<OrganizationDto> selectOrganizationsWithoutLoadedTemplate(DbSession dbSession, String loadedTemplateType, int page, int pageSize) {
-    checkArgument(page >= 1, "page must be >= 1");
-    checkArgument(pageSize >= 1, "page size must be >= 1");
-    int offset = (page - 1) * pageSize;
-    return getMapper(dbSession).selectOrganizationsWithoutLoadedTemplate(loadedTemplateType, page, pageSize, offset);
+  public List<OrganizationDto> selectOrganizationsWithoutLoadedTemplate(DbSession dbSession, String loadedTemplateType, Pagination pagination) {
+    return getMapper(dbSession).selectOrganizationsWithoutLoadedTemplate(loadedTemplateType, pagination);
   }
 
   /**
index 05755c1d04b4121705a851fccca37d88b5016544..cffd15faa829f0f56d028de93e07df6c73f7fd95 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.db.organization;
 import java.util.List;
 import javax.annotation.CheckForNull;
 import org.apache.ibatis.annotations.Param;
+import org.sonar.db.Pagination;
 
 public interface OrganizationMapper {
   void insert(@Param("organization") OrganizationDto organization);
@@ -42,11 +43,9 @@ public interface OrganizationMapper {
   /**
    * Assuming the key of the loaded template with the specified type is an organization's UUID, select all organizations
    * which does not have a row in table LOADED_TEMPLATES with the specified type.
-   *
-   * @param offset {@code ((#{page} - 1) * #{pageSize})}
    */
   List<OrganizationDto> selectOrganizationsWithoutLoadedTemplate(@Param("loadedTemplateType") String type,
-    @Param("page") int page, @Param("pageSize") int pageSize, @Param("offset") int offset);
+    @Param("pagination") Pagination pagination);
 
   DefaultTemplates selectDefaultTemplatesByUuid(@Param("uuid") String uuid);
 
index 826a66b434e7e11c7277173b394f9c6b78b231e6..04913948f182f4ed6d247a4d2c604eaecab40d5f 100644 (file)
     <include refid="sqlSelectOrganizationsWithoutLoadedTemplate"/>
     order by
       org.created_at asc
-    limit #{pageSize} offset #{offset}
+    limit #{pagination.pageSize,jdbcType=INTEGER} offset #{pagination.offset,jdbcType=INTEGER}
   </select>
 
   <select id="selectOrganizationsWithoutLoadedTemplate" parameterType="map" resultType="Organization" databaseId="mssql">
       <include refid="sqlSelectOrganizationsWithoutLoadedTemplate"/>
     ) as query
     where
-      query.number between (#{offset} + 1) and (#{page} * #{pageSize})
+      query.number between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
     order by
       query.createdAt asc
   </select>
       ) t
     ) t
     where
-      t.rn between (#{offset} + 1) and (#{page} * #{pageSize})
+      t.rn between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
   </select>
 
   <sql id="sqlSelectOrganizationsWithoutLoadedTemplate">
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/PaginationTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/PaginationTest.java
new file mode 100644 (file)
index 0000000..e4aa88c
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.db;
+
+import java.util.Random;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.db.Pagination.forPage;
+
+
+public class PaginationTest {
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  @Test
+  public void all_is_page_1_with_MAX_INTEGER_page_size() {
+    Pagination pagination = Pagination.all();
+
+    assertThat(pagination.getPage()).isEqualTo(1);
+    assertThat(pagination.getPageSize()).isEqualTo(Integer.MAX_VALUE);
+  }
+
+  @Test
+  public void all_returns_a_constant() {
+    assertThat(Pagination.all()).isSameAs(Pagination.all());
+  }
+
+  @Test
+  public void forPage_fails_with_IAE_if_page_is_0() {
+    expectedException.expect(IllegalArgumentException.class);
+    expectedException.expectMessage("page index must be >= 1");
+
+    forPage(0);
+  }
+
+  @Test
+  public void forPage_fails_with_IAE_if_page_is_less_than_0() {
+    expectedException.expect(IllegalArgumentException.class);
+    expectedException.expectMessage("page index must be >= 1");
+
+    forPage(-Math.abs(new Random().nextInt()) - 1);
+  }
+
+  @Test
+  public void andSize_fails_with_IAE_if_size_is_0() {
+    Pagination.Builder builder = forPage(1);
+
+    expectedException.expect(IllegalArgumentException.class);
+    expectedException.expectMessage("page size must be >= 1");
+
+    builder.andSize(0);
+  }
+
+  @Test
+  public void andSize_fails_with_IAE_if_size_is_less_than_0() {
+    Pagination.Builder builder = forPage(1);
+
+    expectedException.expect(IllegalArgumentException.class);
+    expectedException.expectMessage("page size must be >= 1");
+
+    builder.andSize(-Math.abs(new Random().nextInt()) - 1);
+  }
+
+  @Test
+  public void offset_is_computed_from_page_and_size() {
+    assertThat(forPage(2).andSize(3).getOffset()).isEqualTo(3);
+    assertThat(forPage(5).andSize(3).getOffset()).isEqualTo(12);
+    assertThat(forPage(5).andSize(1).getOffset()).isEqualTo(4);
+  }
+
+  @Test
+  public void startRowNumber_is_computed_from_page_and_size() {
+    assertThat(forPage(2).andSize(3).getStartRowNumber()).isEqualTo(4);
+    assertThat(forPage(5).andSize(3).getStartRowNumber()).isEqualTo(13);
+    assertThat(forPage(5).andSize(1).getStartRowNumber()).isEqualTo(5);
+  }
+
+  @Test
+  public void endRowNumber_is_computed_from_page_and_size() {
+    assertThat(forPage(2).andSize(3).getEndRowNumber()).isEqualTo(6);
+    assertThat(forPage(5).andSize(3).getEndRowNumber()).isEqualTo(15);
+    assertThat(forPage(5).andSize(1).getEndRowNumber()).isEqualTo(5);
+  }
+}
index 0126857dc15cad31618182077f5b65b215c00cbb..3f3f431dc304b5d7eae099ba868ce67c3c0402c8 100644 (file)
@@ -55,6 +55,8 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.sonar.db.organization.OrganizationQuery.newOrganizationQueryBuilder;
 import static org.sonar.db.organization.OrganizationQuery.returnAll;
+import static org.sonar.db.Pagination.all;
+import static org.sonar.db.Pagination.forPage;
 
 public class OrganizationDaoTest {
   private static final long SOME_DATE = 1_200_999L;
@@ -846,7 +848,7 @@ public class OrganizationDaoTest {
 
   @Test
   public void selectOrganizationsWithoutLoadedTemplate_returns_empty_if_there_is_no_organization() {
-    List<OrganizationDto> organizationDtos = underTest.selectOrganizationsWithoutLoadedTemplate(dbSession, "type1", 1, Integer.MAX_VALUE);
+    List<OrganizationDto> organizationDtos = underTest.selectOrganizationsWithoutLoadedTemplate(dbSession, "type1", all());
 
     assertThat(organizationDtos).isEmpty();
   }
@@ -857,7 +859,7 @@ public class OrganizationDaoTest {
     String[] organizationUuids = IntStream.range(0, organizationCount).mapToObj(i -> "uuid_" + i).toArray(String[]::new);
     Arrays.stream(organizationUuids).forEach(uuid -> dbTester.organizations().insertForUuid(uuid));
 
-    List<OrganizationDto> organizationDtos = underTest.selectOrganizationsWithoutLoadedTemplate(dbSession, "type1", 1, Integer.MAX_VALUE);
+    List<OrganizationDto> organizationDtos = underTest.selectOrganizationsWithoutLoadedTemplate(dbSession, "type1", all());
 
     assertThat(organizationDtos)
       .extracting(OrganizationDto::getUuid)
@@ -880,7 +882,7 @@ public class OrganizationDaoTest {
     dbTester.getDbClient().loadedTemplateDao().insert(new LoadedTemplateDto("", loadedTemplateType), dbSession);
     dbTester.commit();
 
-    List<OrganizationDto> organizationDtos = underTest.selectOrganizationsWithoutLoadedTemplate(dbSession, loadedTemplateType, 1, Integer.MAX_VALUE);
+    List<OrganizationDto> organizationDtos = underTest.selectOrganizationsWithoutLoadedTemplate(dbSession, loadedTemplateType, all());
 
     assertThat(organizationDtos)
       .extracting(OrganizationDto::getUuid)
@@ -896,33 +898,33 @@ public class OrganizationDaoTest {
     when(system2.now()).thenAnswer(t -> alwaysIncreasingSystem2.now());
     IntStream.range(1, 31).forEach(i -> dbTester.organizations().insertForUuid("" + i));
 
-    assertThat(underTest.selectOrganizationsWithoutLoadedTemplate(dbSession, "foo", 1, Integer.MAX_VALUE))
+    assertThat(underTest.selectOrganizationsWithoutLoadedTemplate(dbSession, "foo", all()))
       .extracting(dto -> Integer.valueOf(dto.getUuid()))
       .hasSize(30)
       .allMatch(i -> i > 0 && i <= 30);
-    assertThat(underTest.selectOrganizationsWithoutLoadedTemplate(dbSession, "foo", 1, 30))
+    assertThat(underTest.selectOrganizationsWithoutLoadedTemplate(dbSession, "foo", forPage(1).andSize(30)))
       .extracting(dto -> Integer.valueOf(dto.getUuid()))
       .hasSize(30)
       .allMatch(i -> i > 0 && i <= 30);
-    assertThat(underTest.selectOrganizationsWithoutLoadedTemplate(dbSession, "foo", 1, 10))
+    assertThat(underTest.selectOrganizationsWithoutLoadedTemplate(dbSession, "foo", forPage(1).andSize(10)))
       .extracting(dto -> Integer.valueOf(dto.getUuid()))
       .hasSize(10)
       .allMatch(i -> i > 0 && i <= 10);
-    assertThat(underTest.selectOrganizationsWithoutLoadedTemplate(dbSession, "foo", 2, 10))
+    assertThat(underTest.selectOrganizationsWithoutLoadedTemplate(dbSession, "foo", forPage(2).andSize(10)))
       .extracting(dto -> Integer.valueOf(dto.getUuid()))
       .hasSize(10)
       .allMatch(i -> i > 10 && i <= 20);
-    assertThat(underTest.selectOrganizationsWithoutLoadedTemplate(dbSession, "foo", 5, 5))
+    assertThat(underTest.selectOrganizationsWithoutLoadedTemplate(dbSession, "foo", forPage(5).andSize(5)))
       .extracting(dto -> Integer.valueOf(dto.getUuid()))
       .hasSize(5)
       .allMatch(i -> i > 20 && i <= 25);
-    assertThat(underTest.selectOrganizationsWithoutLoadedTemplate(dbSession, "foo", 6, 5))
+    assertThat(underTest.selectOrganizationsWithoutLoadedTemplate(dbSession, "foo", forPage(6).andSize(5)))
       .extracting(dto -> Integer.valueOf(dto.getUuid()))
       .hasSize(5)
       .allMatch(i -> i > 25 && i <= 30);
-    assertThat(underTest.selectOrganizationsWithoutLoadedTemplate(dbSession, "foo", 7, 5))
+    assertThat(underTest.selectOrganizationsWithoutLoadedTemplate(dbSession, "foo", forPage(7).andSize(5)))
       .isEmpty();
-    assertThat(underTest.selectOrganizationsWithoutLoadedTemplate(dbSession, "foo", 2, 50))
+    assertThat(underTest.selectOrganizationsWithoutLoadedTemplate(dbSession, "foo", forPage(2).andSize(50)))
       .isEmpty();
   }
 
index 45a82ae030fec0a74dd47b503b39bd5c0f2dab5c..3d2480769d7ec39c054ceff52c7f3b5b95e85c15 100644 (file)
@@ -48,6 +48,7 @@ import org.sonar.api.utils.log.Profiler;
 import org.sonar.core.util.stream.Collectors;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
+import org.sonar.db.Pagination;
 import org.sonar.db.loadedtemplate.LoadedTemplateDto;
 import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.qualityprofile.QualityProfileDto;
@@ -60,6 +61,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.apache.commons.codec.binary.Hex.encodeHexString;
 import static org.apache.commons.lang.StringUtils.isNotEmpty;
 import static org.apache.commons.lang.StringUtils.lowerCase;
+import static org.sonar.db.Pagination.forPage;
 import static org.sonar.db.loadedtemplate.LoadedTemplateDto.QUALITY_PROFILE_TYPE;
 
 /**
@@ -70,7 +72,7 @@ public class RegisterQualityProfiles {
 
   private static final Logger LOGGER = Loggers.get(RegisterQualityProfiles.class);
   private static final String DEFAULT_PROFILE_NAME = "Sonar way";
-  private static final int PROCESSED_ORGANIZATIONS_BATCH_SIZE = 2000;
+  private static final Pagination PROCESSED_ORGANIZATIONS_BATCH_SIZE = forPage(1).andSize(2000);
 
   private final List<ProfileDefinition> definitions;
   private final DbClient dbClient;
@@ -83,13 +85,13 @@ public class RegisterQualityProfiles {
    * To be kept when no ProfileDefinition are injected
    */
   public RegisterQualityProfiles(DbClient dbClient,
-                                 QProfileFactory profileFactory, CachingRuleActivator ruleActivator, Languages languages, ActiveRuleIndexer activeRuleIndexer) {
+    QProfileFactory profileFactory, CachingRuleActivator ruleActivator, Languages languages, ActiveRuleIndexer activeRuleIndexer) {
     this(dbClient, profileFactory, ruleActivator, Collections.emptyList(), languages, activeRuleIndexer);
   }
 
   public RegisterQualityProfiles(DbClient dbClient,
-                                 QProfileFactory profileFactory, CachingRuleActivator ruleActivator,
-                                 List<ProfileDefinition> definitions, Languages languages, ActiveRuleIndexer activeRuleIndexer) {
+    QProfileFactory profileFactory, CachingRuleActivator ruleActivator,
+    List<ProfileDefinition> definitions, Languages languages, ActiveRuleIndexer activeRuleIndexer) {
     this.dbClient = dbClient;
     this.profileFactory = profileFactory;
     this.ruleActivator = ruleActivator;
@@ -113,7 +115,7 @@ public class RegisterQualityProfiles {
     try (DbSession session = dbClient.openSession(false)) {
       List<ActiveRuleChange> changes = new ArrayList<>();
       qualityProfilesByLanguage.entrySet()
-          .forEach(entry -> registerPerLanguage(session, entry.getValue(), changes));
+        .forEach(entry -> registerPerLanguage(session, entry.getValue(), changes));
       activeRuleIndexer.index(changes);
       profiler.stopDebug();
     }
@@ -138,31 +140,31 @@ public class RegisterQualityProfiles {
 
   private void validateAndClean(ListMultimap<String, RulesProfile> byLang) {
     byLang.asMap().entrySet()
-        .removeIf(entry -> {
-          String language = entry.getKey();
-          if (languages.get(language) == null) {
-            LOGGER.info("Language {} is not installed, related Quality profiles are ignored", language);
-            return true;
-          }
-          Collection<RulesProfile> profiles = entry.getValue();
-          if (profiles.isEmpty()) {
-            LOGGER.warn("No Quality profiles defined for language: {}", language);
-            return true;
-          }
-          return false;
-        });
+      .removeIf(entry -> {
+        String language = entry.getKey();
+        if (languages.get(language) == null) {
+          LOGGER.info("Language {} is not installed, related Quality profiles are ignored", language);
+          return true;
+        }
+        Collection<RulesProfile> profiles = entry.getValue();
+        if (profiles.isEmpty()) {
+          LOGGER.warn("No Quality profiles defined for language: {}", language);
+          return true;
+        }
+        return false;
+      });
   }
 
   private Map<String, List<QualityProfile>> toQualityProfilesByLanguage(ListMultimap<String, RulesProfile> rulesProfilesByLanguage) {
     Map<String, List<QualityProfile.Builder>> buildersByLanguage = Multimaps.asMap(rulesProfilesByLanguage)
-        .entrySet()
-        .stream()
-        .collect(Collectors.uniqueIndex(Map.Entry::getKey, RegisterQualityProfiles::toQualityProfileBuilders));
+      .entrySet()
+      .stream()
+      .collect(Collectors.uniqueIndex(Map.Entry::getKey, RegisterQualityProfiles::toQualityProfileBuilders));
     return buildersByLanguage
-        .entrySet()
-        .stream()
-        .filter(RegisterQualityProfiles::ensureAtMostOneDeclaredDefault)
-        .collect(Collectors.uniqueIndex(Map.Entry::getKey, entry -> toQualityProfiles(entry.getValue()), buildersByLanguage.size()));
+      .entrySet()
+      .stream()
+      .filter(RegisterQualityProfiles::ensureAtMostOneDeclaredDefault)
+      .collect(Collectors.uniqueIndex(Map.Entry::getKey, entry -> toQualityProfiles(entry.getValue()), buildersByLanguage.size()));
   }
 
   /**
@@ -183,8 +185,8 @@ public class RegisterQualityProfiles {
     Map<String, QualityProfile.Builder> qualityProfileBuildersByName = new LinkedHashMap<>();
     for (RulesProfile rulesProfile : rulesProfilesByLanguage.getValue()) {
       qualityProfileBuildersByName.compute(
-          rulesProfile.getName(),
-          (name, existingBuilder) -> updateOrCreateBuilder(language, existingBuilder, rulesProfile, name));
+        rulesProfile.getName(),
+        (name, existingBuilder) -> updateOrCreateBuilder(language, existingBuilder, rulesProfile, name));
     }
     return ImmutableList.copyOf(qualityProfileBuildersByName.values());
   }
@@ -194,9 +196,9 @@ public class RegisterQualityProfiles {
    */
   private static boolean ensureAtMostOneDeclaredDefault(Map.Entry<String, List<QualityProfile.Builder>> entry) {
     Set<String> declaredDefaultProfileNames = entry.getValue().stream()
-        .filter(QualityProfile.Builder::isDeclaredDefault)
-        .map(QualityProfile.Builder::getName)
-        .collect(Collectors.toSet());
+      .filter(QualityProfile.Builder::isDeclaredDefault)
+      .map(QualityProfile.Builder::getName)
+      .collect(Collectors.toSet());
     checkState(declaredDefaultProfileNames.size() <= 1, "Several Quality profiles are flagged as default for the language %s: %s", entry.getKey(), declaredDefaultProfileNames);
     return true;
   }
@@ -205,16 +207,16 @@ public class RegisterQualityProfiles {
     QualityProfile.Builder builder = existingBuilder;
     if (builder == null) {
       builder = new QualityProfile.Builder()
-          .setLanguage(language)
-          .setName(name);
+        .setLanguage(language)
+        .setName(name);
     }
     Boolean defaultProfile = rulesProfile.getDefaultProfile();
     boolean declaredDefault = defaultProfile != null && defaultProfile;
     return builder
-        // if there is multiple RulesProfiles with the same name, if at least one is declared default,
-        // then QualityProfile is flagged as declared default
-        .setDeclaredDefault(builder.declaredDefault || declaredDefault)
-        .addRules(rulesProfile.getActiveRules());
+      // if there is multiple RulesProfiles with the same name, if at least one is declared default,
+      // then QualityProfile is flagged as declared default
+      .setDeclaredDefault(builder.declaredDefault || declaredDefault)
+      .addRules(rulesProfile.getActiveRules());
   }
 
   private static List<QualityProfile> toQualityProfiles(List<QualityProfile.Builder> builders) {
@@ -228,8 +230,8 @@ public class RegisterQualityProfiles {
     }
     MessageDigest md5Digest = DigestUtils.getMd5Digest();
     return builders.stream()
-        .map(builder -> builder.build(md5Digest))
-        .collect(Collectors.toList(builders.size()));
+      .map(builder -> builder.build(md5Digest))
+      .collect(Collectors.toList(builders.size()));
   }
 
   private void registerPerLanguage(DbSession session, List<QualityProfile> qualityProfiles, List<ActiveRuleChange> changes) {
@@ -248,7 +250,7 @@ public class RegisterQualityProfiles {
 
   private List<OrganizationDto> getOrganizationsWithoutQP(DbSession session, QualityProfile qualityProfile) {
     return dbClient.organizationDao().selectOrganizationsWithoutLoadedTemplate(session,
-        qualityProfile.getLoadedTemplateType(), 1, PROCESSED_ORGANIZATIONS_BATCH_SIZE);
+      qualityProfile.getLoadedTemplateType(), PROCESSED_ORGANIZATIONS_BATCH_SIZE);
   }
 
   private void registerPerQualityProfileAndOrganization(DbSession session, QualityProfile qualityProfile, OrganizationDto organization, List<ActiveRuleChange> changes) {