<commit_before>package uk.ac.ed.learn9.bb.timetabling.service;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Service for monitoring which courses in Learn are synchronised from EUGEX.
 */
@Service
public class EugexService {
    @Autowired
    private DataSource stagingDataSource;
    @Autowired
    private DataSource eugexDataSource;

    /**
     * Synchronises details of courses in EUGEX marked as active in the VLE,
     * to the staging database.
     * @throws SQLException 
     */
    public void synchroniseVleActiveCourses()
            throws SQLException {
        final Connection stagingDatabase = this.getStagingDataSource().getConnection();
        try {
            final Connection eugexDatabase = this.getEugexDataSource().getConnection();
            try {
                this.synchroniseVleActiveCourses(stagingDatabase, eugexDatabase);
            } finally {
                eugexDatabase.close();
            }
        } finally {
            stagingDatabase.close();
        }
    }

    /**
     * Synchronises details of courses that are copied from EUGEX to Learn,
     * from the EUGEX database into the staging database.
     * 
     * @param stagingDatabase a connection to the staging database.
     * @param eugexDatabase a connection to the EUGEX database.
     * @throws SQLException 
     */
    private void synchroniseVleActiveCourses(final Connection stagingDatabase, final Connection eugexDatabase)
        throws SQLException {
        stagingDatabase.setAutoCommit(false);
        try {
            final PreparedStatement sourceStatement = eugexDatabase.prepareStatement(
                "SELECT VCL1_COURSE_CODE course_code, VCL2_COURSE_OCCURENCE occurrence_code, "
                        + "VCL3_COURSE_YEAR_CODE academic_year, VCL4_COURSE_PERIOD period_code, VCL13_WEBCT_ACTIVE webct_active "
                    + "FROM EUGEX_VLE_COURSES_VW "
                    + "ORDER BY VCL3_COURSE_YEAR_CODE, VCL1_COURSE_CODE, VCL2_COURSE_OCCURENCE, VCL4_COURSE_PERIOD"
                
            );
            try {
                final PreparedStatement destinationStatement = stagingDatabase.prepareStatement(
                    "SELECT tt_module_id, webct_active, occurrence_course_code course_code, "
                            + "cache_occurrence_code occurrence_code, tt_academic_year academic_year, "
                            + "cache_semester_code period_code "
                        + "FROM module "
                        + "WHERE occurrence_course_code IS NOT NULL "
                            + "AND tt_academic_year IS NOT NULL "
                        + "ORDER BY tt_academic_year, occurrence_course_code, cache_occurrence_code, cache_semester_code",
                    ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE
                );
                try {
                    final ResultSet sourceRs = sourceStatement.executeQuery();
                    try {
                        final ResultSet destinationRs = destinationStatement.executeQuery();
                        try {
                            this.doSynchroniseVleActiveCourses(destinationRs, sourceRs);<commit_msg>Corrected field names in EugexService<commit_after>package uk.ac.ed.learn9.bb.timetabling.service;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Service for monitoring which courses in Learn are synchronised from EUGEX.
 */
@Service
public class EugexService {
    @Autowired
    private DataSource stagingDataSource;
    @Autowired
    private DataSource eugexDataSource;

    /**
     * Synchronises details of courses in EUGEX marked as active in the VLE,
     * to the staging database.
     * @throws SQLException 
     */
    public void synchroniseVleActiveCourses()
            throws SQLException {
        final Connection stagingDatabase = this.getStagingDataSource().getConnection();
        try {
            final Connection eugexDatabase = this.getEugexDataSource().getConnection();
            try {
                this.synchroniseVleActiveCourses(stagingDatabase, eugexDatabase);
            } finally {
                eugexDatabase.close();
            }
        } finally {
            stagingDatabase.close();
        }
    }

    /**
     * Synchronises details of courses that are copied from EUGEX to Learn,
     * from the EUGEX database into the staging database.
     * 
     * @param stagingDatabase a connection to the staging database.
     * @param eugexDatabase a connection to the EUGEX database.
     * @throws SQLException 
     */
    private void synchroniseVleActiveCourses(final Connection stagingDatabase, final Connection eugexDatabase)
        throws SQLException {
        stagingDatabase.setAutoCommit(false);
        try {
            final PreparedStatement sourceStatement = eugexDatabase.prepareStatement(
                "SELECT VCL1_COURSE_CODE course_code, VCL2_COURSE_OCCURENCE occurrence_code, "
                        + "VCL3_COURSE_YEAR_CODE academic_year, VCL4_COURSE_PERIOD period_code, VCL13_WEBCT_ACTIVE webct_active "
                    + "FROM EUGEX_VLE_COURSES_VW "
                    + "ORDER BY VCL3_COURSE_YEAR_CODE, VCL1_COURSE_CODE, VCL2_COURSE_OCCURENCE, VCL4_COURSE_PERIOD"
                
            );
            try {
                final PreparedStatement destinationStatement = stagingDatabase.prepareStatement(
                    "SELECT tt_module_id, webct_active, cache_course_code course_code, "
                            + "cache_occurrence_code occurrence_code, tt_academic_year academic_year, "
                            + "cache_semester_code period_code "
                        + "FROM module "
                        + "WHERE cache_course_code IS NOT NULL "
                            + "AND tt_academic_year IS NOT NULL "
                        + "ORDER BY tt_academic_year, cache_course_code, cache_occurrence_code, cache_semester_code",
                    ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE
                );
                try {
                    final ResultSet sourceRs = sourceStatement.executeQuery();
                    try {
                        final ResultSet destinationRs = destinationStatement.executeQuery();
                        try {
                            this.doSynchroniseVleActiveCourses(destinationRs, sourceRs);
{'fraction_non_alphanumeric': 0.06072218128224024, 'fraction_numerical': 0.0032424465733235075, 'mean_word_length': 2.1934117647058824, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1089997', 'n_tokens_mistral': 1841, 'n_tokens_neox': 1762, 'n_words': 401}