import java.util.Locale;
import java.util.Map;
import java.util.Set;
+import javax.annotation.Nullable;
import org.sonar.api.Startable;
import org.sonar.api.config.Configuration;
import org.sonar.api.platform.Server;
import org.sonar.api.server.ws.WebService.NewController;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.api.web.page.Page;
-import org.sonar.core.platform.EditionProvider;
import org.sonar.core.platform.PlatformEditionProvider;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import static org.sonar.core.config.WebConstants.SONAR_LF_GRAVATAR_SERVER_URL;
import static org.sonar.core.config.WebConstants.SONAR_LF_LOGO_URL;
import static org.sonar.core.config.WebConstants.SONAR_LF_LOGO_WIDTH_PX;
+import static org.sonar.core.platform.EditionProvider.Edition;
import static org.sonar.core.platform.EditionProvider.Edition.DATACENTER;
import static org.sonar.core.platform.EditionProvider.Edition.ENTERPRISE;
import static org.sonar.process.ProcessProperties.Property.SONARCLOUD_ENABLED;
RATING_GRID,
DEVELOPER_AGGREGATED_INFO_DISABLED);
+ private static final String REGULATORY_REPORT_FEATURE_ENABLED_FLAG = "regulatoryReportFeatureEnabled";
+
private final Map<String, String> systemSettingValuesByKey;
private final PageRepository pageRepository;
writeInstanceUsesDefaultAdminCredentials(json);
writeMultipleAlmEnabled(json);
writeProjectImportFeature(json);
+ writeRegulatoryReportFeature(json);
editionProvider.get().ifPresent(e -> json.prop("edition", e.name().toLowerCase(Locale.ENGLISH)));
writeNeedIssueSync(json);
json.prop("standalone", webServer.isStandalone());
}
private void writeProjectImportFeature(JsonWriter json) {
- EditionProvider.Edition edition = editionProvider.get().orElse(null);
- boolean isEnabled = Arrays.asList(ENTERPRISE, DATACENTER).contains(edition);
+ Edition edition = editionProvider.get().orElse(null);
+ boolean isEnabled = isEditionEEorDCE(edition);
json.prop("projectImportFeatureEnabled", isEnabled);
}
private void writeWebAnalytics(JsonWriter json) {
webAnalyticsLoader.getUrlPathToJs().ifPresent(p -> json.prop("webAnalyticsJsPath", p));
}
+
+ private void writeRegulatoryReportFeature(JsonWriter json) {
+ Edition edition = editionProvider.get().orElse(null);
+ boolean isEnabled = isEditionEEorDCE(edition);
+ json.prop(REGULATORY_REPORT_FEATURE_ENABLED_FLAG, isEnabled);
+ }
+
+ private static boolean isEditionEEorDCE(@Nullable Edition edition) {
+ return Arrays.asList(ENTERPRISE, DATACENTER).contains(edition);
+ }
}
assertJson(call()).isSimilarTo("{\"projectImportFeatureEnabled\":false}");
}
+
@Test
public void return_need_issue_sync() {
init();
assertJson(call()).isSimilarTo("{\"canAdmin\":true}");
}
+ @Test
+ public void regulatory_report_feature_enabled_ee_dce() {
+ init();
+ when(editionProvider.get()).thenReturn(Optional.of(ENTERPRISE));
+ assertJson(call()).isSimilarTo("{\"regulatoryReportFeatureEnabled\":true}");
+
+ when(editionProvider.get()).thenReturn(Optional.of(DATACENTER));
+ assertJson(call()).isSimilarTo("{\"regulatoryReportFeatureEnabled\":true}");
+ }
+
+ @Test
+ public void regulatory_report_feature_disabled_ce_de() {
+ init();
+ when(editionProvider.get()).thenReturn(Optional.of(COMMUNITY));
+ assertJson(call()).isSimilarTo("{\"regulatoryReportFeatureEnabled\":false}");
+
+ when(editionProvider.get()).thenReturn(Optional.of(DEVELOPER));
+ assertJson(call()).isSimilarTo("{\"regulatoryReportFeatureEnabled\":false}");
+
+ when(editionProvider.get()).thenReturn(Optional.empty());
+ assertJson(call()).isSimilarTo("{\"regulatoryReportFeatureEnabled\":false}");
+ }
+
@Test
public void instance_uses_default_admin_credentials() {
init();