<commit_before>package ca.corefacility.bioinformatics.irida.database.changesets;

import java.util.Date;
import java.util.List;

import javax.sql.DataSource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;

import ca.corefacility.bioinformatics.irida.config.data.IridaApiJdbcDataSourceConfig;
import ca.corefacility.bioinformatics.irida.model.subscription.ProjectSubscription;

import liquibase.change.custom.CustomSqlChange;
import liquibase.database.Database;
import liquibase.exception.CustomChangeException;
import liquibase.exception.SetupException;
import liquibase.exception.ValidationErrors;
import liquibase.resource.ResourceAccessor;
import liquibase.statement.SqlStatement;

/**
 * Liquibase update to create {@link ProjectSubscription} entries for every project that a user has access to.
 */
public class ProjectEmailSubscriptionMigration implements CustomSqlChange {

	private static final Logger logger = LoggerFactory.getLogger(ProjectEmailSubscriptionMigration.class);
	private DataSource dataSource;

	@Override
	public SqlStatement[] generateStatements(Database database) throws CustomChangeException {
		JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
		// Get all the current user project level access
		List<ProjectEmailSubscriptionMigration.ProjectSubscriptionResult> projectSubscriptionResults = jdbcTemplate.query(
				"SELECT * FROM project_user", (rs, rowNum) -> {
					return new ProjectSubscriptionResult(rs.getLong("project_id"), rs.getLong("user_id"),
							rs.getBoolean("email_subscription"));
				});

		// Create a new ProjectSubscription entry for each user project level access
		for (ProjectEmailSubscriptionMigration.ProjectSubscriptionResult projectSubscriptionResult : projectSubscriptionResults) {
			jdbcTemplate.update(
					"INSERT INTO project_subscription (project_id, user_id, email_subscription, created_date) VALUES (?,?,?,?)",
					projectSubscriptionResult.projectId, projectSubscriptionResult.userId,
					projectSubscriptionResult.emailSubscription, new Date());
		}

		// Get all the current group project level access

		return new SqlStatement[0];
	}

	@Override
	public String getConfirmationMessage() {
		return "Successfully created project subscriptions for every project a user has access to";
	}

	@Override
	public void setUp() throws SetupException {
		logger.info("Starting to create project subscriptions for every project a user has access to");
	}
<commit_msg>starting to create a CustomSqlChange to migrate project subscription data<commit_after>package ca.corefacility.bioinformatics.irida.database.changesets;

import java.util.Date;
import java.util.List;

import javax.sql.DataSource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;

import ca.corefacility.bioinformatics.irida.config.data.IridaApiJdbcDataSourceConfig;
import ca.corefacility.bioinformatics.irida.model.subscription.ProjectSubscription;

import liquibase.change.custom.CustomSqlChange;
import liquibase.database.Database;
import liquibase.exception.CustomChangeException;
import liquibase.exception.SetupException;
import liquibase.exception.ValidationErrors;
import liquibase.resource.ResourceAccessor;
import liquibase.statement.SqlStatement;

/**
 * Liquibase update to create {@link ProjectSubscription} entries for every project that a user has access to.
 */
public class ProjectEmailSubscriptionMigration implements CustomSqlChange {

	private static final Logger logger = LoggerFactory.getLogger(ProjectEmailSubscriptionMigration.class);
	private DataSource dataSource;

	@Override
	public SqlStatement[] generateStatements(Database database) throws CustomChangeException {
		JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
		// Get all the current project & group level access
		List<ProjectEmailSubscriptionMigration.ProjectSubscriptionResult> projectSubscriptionResults = jdbcTemplate.query(
				"SELECT project_id, user_id, email_subscription FROM project_user UNION SELECT p.project_id, m.user_id, 0 from user_group_member m LEFT JOIN user_group_project p ON m.group_id = p.user_group_id;",
				(rs, rowNum) -> {
					return new ProjectSubscriptionResult(rs.getLong("project_id"), rs.getLong("user_id"),
							rs.getBoolean("email_subscription"));
				});

		// Create a new ProjectSubscription entry for each project & group level access
		for (ProjectEmailSubscriptionMigration.ProjectSubscriptionResult projectSubscriptionResult : projectSubscriptionResults) {
			jdbcTemplate.update(
					"INSERT INTO project_subscription (project_id, user_id, email_subscription, created_date) VALUES (?,?,?,?)",
					projectSubscriptionResult.projectId, projectSubscriptionResult.userId,
					projectSubscriptionResult.emailSubscription, new Date());
		}

		return new SqlStatement[0];
	}

	@Override
	public String getConfirmationMessage() {
		return "Successfully created project subscriptions for every project a user has access to";
	}

	@Override
	public void setUp() throws SetupException {
		logger.info("Starting to create project subscriptions for every project a user has access to");
	}

{'fraction_non_alphanumeric': 0.07722809667673716, 'fraction_numerical': 0.0013217522658610272, 'mean_word_length': 6.2760989010989015, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '685913', 'n_tokens_mistral': 1456, 'n_tokens_neox': 1367, 'n_words': 363}