<commit_before>package com.bls;

import com.bls.AugmentedConfiguration.DbType;
import com.bls.auth.basic.BasicAuthenticator;
import com.bls.client.opendata.OpenDataClientModule;
import com.bls.core.user.User;
import com.bls.dao.ResetPasswordTokenDao;
import com.bls.dao.UserDao;
import com.bls.mongodb.MongodbModule;
import com.bls.rdbms.RdbmsModule;
import com.bls.resetpwd.InvalidateTokenTask;
import com.google.inject.Injector;
import com.google.inject.Stage;
import com.hubspot.dropwizard.guice.GuiceBundle;
import com.hubspot.dropwizard.guice.GuiceBundle.Builder;
import io.dropwizard.Application;
import io.dropwizard.auth.AuthFactory;
import io.dropwizard.auth.CachingAuthenticator;
import io.dropwizard.auth.basic.BasicAuthFactory;
import io.dropwizard.configuration.SubstitutingSourceProvider;
import io.dropwizard.db.DataSourceFactory;
import io.dropwizard.migrations.MigrationsBundle;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import org.apache.commons.lang3.text.StrLookup;
import org.apache.commons.lang3.text.StrSubstitutor;
import org.glassfish.hk2.utilities.Binder;

import static com.bls.AugmentedConfiguration.DBTYPE_PROPERTY_NAME;
import static com.bls.AugmentedConfiguration.RDBMS_ENTITIES_PACKAGE;

public class AugmentedApplication extends Application<AugmentedConfiguration> {

    private Injector injector;

    public static void main(final String[] args) throws Exception {
        new AugmentedApplication().run(args);
    }

    private static boolean isDbTypeSetToMongodb(final String dbTypePropertyValue) {
        return dbTypePropertyValue == null || DbType.MONGODB.name().equalsIgnoreCase(dbTypePropertyValue);
    }

    @Override
    public String getName() {
        return this.getClass().getSimpleName();
    }

    @Override
    public void initialize(final Bootstrap<AugmentedConfiguration> bootstrap) {

        // Enable configuration variable substitution with system property values
        final StrSubstitutor systemPropertyStrSubstitutor = new StrSubstitutor(StrLookup.systemPropertiesLookup());
        bootstrap.setConfigurationSourceProvider(
                new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(), systemPropertyStrSubstitutor));

        // setup guice builder
        final Builder<AugmentedConfiguration> guiceConfiguration = GuiceBundle.<AugmentedConfiguration>newBuilder() //
                .addModule(new AugmentedModule()) //
                .addModule(new OpenDataClientModule()) //
                .enableAutoConfig(getClass().getPackage().getName()) //
                .setConfigClass(AugmentedConfiguration.class);

        // setup db backend based - choice i based on system property value
        if (isDbTypeSetToMongodb(systemPropertyStrSubstitutor.getVariableResolver().lookup(DBTYPE_PROPERTY_NAME))) {
            guiceConfiguration.addModule(new MongodbModule());
        } else {
            bootstrap.addBundle(createMigrationBundle());
            guiceConfiguration.addModule(new RdbmsModule<AugmentedConfiguration>(bootstrap) {
                @Override
                public DataSourceFactory getRealDataSourceFactory(final AugmentedConfiguration configuration) {
                    return configuration.getRdbmsConfig();
                }

                @Override
                public String getPackagesToScanForEntities() {
                    return RDBMS_ENTITIES_PACKAGE;
                }
            });
        }

        // eagerly inject all dependencies: note Stage.DEVELOPMENT it's a hack
        final GuiceBundle<AugmentedConfiguration> guiceBundle = guiceConfiguration.build(Stage.DEVELOPMENT);
        bootstrap.addBundle(guiceBundle);

        injector = guiceBundle.getInjector();
    }

    private MigrationsBundle<AugmentedConfiguration> createMigrationBundle() {
        return new MigrationsBundle<AugmentedConfiguration>() {
            @Override
            public DataSourceFactory getDataSourceFactory(final AugmentedConfiguration configuration) {
                return configuration.getRdbmsConfig();
            }
        };
    }

    @Override
    public void run(final AugmentedConfiguration augmentedConfiguration, final Environment environment) throws Exception {
        registerAuthorizationProviders(augmentedConfiguration, environment);
    }

    private void registerAuthorizationProviders(final AugmentedConfiguration augmentedConfiguration, final Environment environment) {
        final UserDao userDao = injector.getInstance(UserDao.class);
        final ResetPasswordTokenDao tokenDao = injector.getInstance(ResetPasswordTokenDao.class);
        final BasicAuthenticator basicAuthenticator = new BasicAuthenticator(userDao);
        final CachingAuthenticator cachingAuthenticator = new CachingAuthenticator(environment.metrics(), basicAuthenticator,
                augmentedConfiguration.getAuthCacheBuilder());
        final Binder authBinder = AuthFactory.binder(new BasicAuthFactory(cachingAuthenticator, "Basic auth", User.class));
        environment.jersey().register(authBinder);
        environment.admin().addTask(new InvalidateTokenTask(tokenDao));
    }
}
<commit_msg>Moved task registration to separate method<commit_after>package com.bls;

import com.bls.AugmentedConfiguration.DbType;
import com.bls.auth.basic.BasicAuthenticator;
import com.bls.client.opendata.OpenDataClientModule;
import com.bls.core.user.User;
import com.bls.dao.ResetPasswordTokenDao;
import com.bls.dao.UserDao;
import com.bls.mongodb.MongodbModule;
import com.bls.rdbms.RdbmsModule;
import com.bls.resetpwd.InvalidateTokenTask;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JSR310Module;
import com.google.inject.Injector;
import com.google.inject.Stage;
import com.hubspot.dropwizard.guice.GuiceBundle;
import com.hubspot.dropwizard.guice.GuiceBundle.Builder;
import io.dropwizard.Application;
import io.dropwizard.auth.AuthFactory;
import io.dropwizard.auth.CachingAuthenticator;
import io.dropwizard.auth.basic.BasicAuthFactory;
import io.dropwizard.configuration.SubstitutingSourceProvider;
import io.dropwizard.db.DataSourceFactory;
import io.dropwizard.jersey.jackson.JacksonMessageBodyProvider;
import io.dropwizard.migrations.MigrationsBundle;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import org.apache.commons.lang3.text.StrLookup;
import org.apache.commons.lang3.text.StrSubstitutor;
import org.glassfish.hk2.utilities.Binder;

import static com.bls.AugmentedConfiguration.DBTYPE_PROPERTY_NAME;
import static com.bls.AugmentedConfiguration.RDBMS_ENTITIES_PACKAGE;

public class AugmentedApplication extends Application<AugmentedConfiguration> {

    private Injector injector;

    public static void main(final String[] args) throws Exception {
        new AugmentedApplication().run(args);
    }

    private static boolean isDbTypeSetToMongodb(final String dbTypePropertyValue) {
        return dbTypePropertyValue == null || DbType.MONGODB.name().equalsIgnoreCase(dbTypePropertyValue);
    }

    @Override
    public String getName() {
        return this.getClass().getSimpleName();
    }

    @Override
    public void initialize(final Bootstrap<AugmentedConfiguration> bootstrap) {

        // Enable configuration variable substitution with system property values
        final StrSubstitutor systemPropertyStrSubstitutor = new StrSubstitutor(StrLookup.systemPropertiesLookup());
        bootstrap.setConfigurationSourceProvider(
                new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(), systemPropertyStrSubstitutor));

        // setup guice builder
        final Builder<AugmentedConfiguration> guiceConfiguration = GuiceBundle.<AugmentedConfiguration>newBuilder() //
                .addModule(new AugmentedModule()) //
                .addModule(new OpenDataClientModule()) //
                .enableAutoConfig(getClass().getPackage().getName()) //
                .setConfigClass(AugmentedConfiguration.class);

        // setup db backend based - choice i based on system property value
        if (isDbTypeSetToMongodb(systemPropertyStrSubstitutor.getVariableResolver().lookup(DBTYPE_PROPERTY_NAME))) {
            guiceConfiguration.addModule(new MongodbModule());
        } else {
            bootstrap.addBundle(createMigrationBundle());
            guiceConfiguration.addModule(new RdbmsModule<AugmentedConfiguration>(bootstrap) {
                @Override
                public DataSourceFactory getRealDataSourceFactory(final AugmentedConfiguration configuration) {
                    return configuration.getRdbmsConfig();
                }

                @Override
                public String getPackagesToScanForEntities() {
                    return RDBMS_ENTITIES_PACKAGE;
                }
            });
        }

        // eagerly inject all dependencies: note Stage.DEVELOPMENT it's a hack
        final GuiceBundle<AugmentedConfiguration> guiceBundle = guiceConfiguration.build(Stage.DEVELOPMENT);
        bootstrap.addBundle(guiceBundle);

        injector = guiceBundle.getInjector();
    }

    private MigrationsBundle<AugmentedConfiguration> createMigrationBundle() {
        return new MigrationsBundle<AugmentedConfiguration>() {
            @Override
            public DataSourceFactory getDataSourceFactory(final AugmentedConfiguration configuration) {
                return configuration.getRdbmsConfig();
            }
        };
    }

    @Override
    public void run(final AugmentedConfiguration augmentedConfiguration, final Environment environment) throws Exception {
        registerAuthorizationProviders(augmentedConfiguration, environment);
        registerInvalidateTokensTask(augmentedConfiguration, environment);
    }


    private void registerAuthorizationProviders(final AugmentedConfiguration augmentedConfiguration, final Environment environment) {
        final UserDao userDao = injector.getInstance(UserDao.class);
        final BasicAuthenticator basicAuthenticator = new BasicAuthenticator(userDao);
        final CachingAuthenticator cachingAuthenticator = new CachingAuthenticator(environment.metrics(), basicAuthenticator,
                augmentedConfiguration.getAuthCacheBuilder());
        final Binder authBinder = AuthFactory.binder(new BasicAuthFactory(cachingAuthenticator, "Basic auth", User.class));
        environment.jersey().register(authBinder);
    }

    private void registerInvalidateTokensTask(final AugmentedConfiguration augmentedConfiguration, final Environment environment) {
        final ResetPasswordTokenDao tokenDao = injector.getInstance(ResetPasswordTokenDao.class);
        environment.admin().addTask(new InvalidateTokenTask(tokenDao));
    }
}

{'fraction_non_alphanumeric': 0.07802268744812321, 'fraction_numerical': 0.0011067047864982017, 'mean_word_length': 3.913457181694608, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7315023', 'n_tokens_mistral': 2868, 'n_tokens_neox': 2736, 'n_words': 509}