<commit_before>package org.tuxdevelop.spring.batch.lightmin.api.resource;

import org.tuxdevelop.spring.batch.lightmin.admin.domain.*;
import org.tuxdevelop.spring.batch.lightmin.api.resource.admin.JobConfigurations;
import org.tuxdevelop.spring.batch.lightmin.api.resource.common.JobParameter;
import org.tuxdevelop.spring.batch.lightmin.api.resource.common.JobParameters;
import org.tuxdevelop.spring.batch.lightmin.api.resource.common.ParameterType;
import org.tuxdevelop.spring.batch.lightmin.exception.SpringBatchLightminApplicationException;

import java.util.*;

/**
 * @author <NAME>
 * @since 0.3
 */
public final class ResourceToAdminMapper {

    private ResourceToAdminMapper() {
    }

    public static Collection<JobConfiguration> map(final JobConfigurations jobConfigurations) {
        final Collection<JobConfiguration> response = new LinkedList<>();
        for (final org.tuxdevelop.spring.batch.lightmin.api.resource.admin.JobConfiguration jobConfiguration : jobConfigurations.getJobConfigurations()) {
            final JobConfiguration jobConfigurationResponse = map(jobConfiguration);
            response.add(jobConfigurationResponse);
        }
        return response;
    }

    public static JobConfiguration map(final org.tuxdevelop.spring.batch.lightmin.api.resource.admin.JobConfiguration jobConfiguration) {
        final JobConfiguration response = new JobConfiguration();
        response.setJobName(jobConfiguration.getJobName());
        response.setJobConfigurationId(jobConfiguration.getJobConfigurationId());
        response.setJobParameters(mapToMap(jobConfiguration.getJobParameters()));
        response.setJobIncrementer(map(jobConfiguration.getJobIncrementer()));
        response.setJobSchedulerConfiguration(map(jobConfiguration.getJobSchedulerConfiguration()));
        response.setJobListenerConfiguration(map(jobConfiguration.getJobListenerConfiguration()));
        return response;
    }

    public static org.springframework.batch.core.JobParameters map(final JobParameters jobParameters) {
        final Map<String, org.springframework.batch.core.JobParameter> parametersMap = new HashMap<>();
        if (jobParameters != null) {
            for (final Map.Entry<String, JobParameter> entry : jobParameters.getParameters().entrySet()) {
                final org.springframework.batch.core.JobParameter.ParameterType parameterType = map(entry.getValue()
                        .getParameterType());
                final org.springframework.batch.core.JobParameter jobParameter;
                switch (parameterType) {
                    case STRING:
                        jobParameter = new org.springframework.batch.core.JobParameter((String) entry.getValue()
                                .getParameter());
                        break;
                    case DOUBLE:
                        jobParameter = new org.springframework.batch.core.JobParameter((Double) entry.getValue()
                                .getParameter());
                        break;
                    case LONG:
                        jobParameter = new org.springframework.batch.core.JobParameter((Long) entry.getValue()
                                .getParameter());
                        break;
                    case DATE:
                        jobParameter = new org.springframework.batch.core.JobParameter((Date) entry.getValue()
                                .getParameter());
                        break;
                    default:
                        throw new SpringBatchLightminApplicationException("Unknown JobParameterType: " + entry.getValue().getParameterType());
                }
                parametersMap.put(entry.getKey(), jobParameter);
            }
        }
        return new org.springframework.batch.core.JobParameters(parametersMap);
    }

    private static JobSchedulerConfiguration map(final org.tuxdevelop.spring.batch.lightmin.api.resource.admin.JobSchedulerConfiguration jobSchedulerConfiguration) {
        final JobSchedulerConfiguration response;
        if (jobSchedulerConfiguration != null) {
            response = new JobSchedulerConfiguration();
            response.setJobSchedulerType(map(jobSchedulerConfiguration.getJobSchedulerType()));
            response.setCronExpression(jobSchedulerConfiguration.getCronExpression());
            response.setFixedDelay(jobSchedulerConfiguration.getFixedDelay());
            response.setInitialDelay(jobSchedulerConfiguration.getInitialDelay());
            response.setSchedulerStatus(map(jobSchedulerConfiguration.getSchedulerStatus()));
            response.setTaskExecutorType(map(jobSchedulerConfiguration.getTaskExecutorType()));
        } else {
            response = null;
        }
        return response;
    }

    private static JobListenerConfiguration map(final org.tuxdevelop.spring.batch.lightmin.api.resource.admin.JobListenerConfiguration jobListenerConfiguration) {

        final JobListenerConfiguration response;
        if (jobListenerConfiguration != null) {
            response = new JobListenerConfiguration();<commit_msg>Solving an issue when launching jobs using parameters, converting the oncoming parameter to the target type, not just casting. For example: - Long: The parameter arrives as Integer (when it's a very short number -> 32 bits) and can't be cast to Long the way it's current done. - Date: The parameter arrives as Long (timestamp) and can't be cast to Date the way it's current done.<commit_after>package org.tuxdevelop.spring.batch.lightmin.api.resource;

import org.tuxdevelop.spring.batch.lightmin.admin.domain.*;
import org.tuxdevelop.spring.batch.lightmin.api.resource.admin.JobConfigurations;
import org.tuxdevelop.spring.batch.lightmin.api.resource.common.JobParameter;
import org.tuxdevelop.spring.batch.lightmin.api.resource.common.JobParameters;
import org.tuxdevelop.spring.batch.lightmin.api.resource.common.ParameterType;
import org.tuxdevelop.spring.batch.lightmin.exception.SpringBatchLightminApplicationException;

import java.util.*;

/**
 * @author <NAME>
 * @since 0.3
 */
public final class ResourceToAdminMapper {

    private ResourceToAdminMapper() {
    }

    public static Collection<JobConfiguration> map(final JobConfigurations jobConfigurations) {
        final Collection<JobConfiguration> response = new LinkedList<>();
        for (final org.tuxdevelop.spring.batch.lightmin.api.resource.admin.JobConfiguration jobConfiguration : jobConfigurations.getJobConfigurations()) {
            final JobConfiguration jobConfigurationResponse = map(jobConfiguration);
            response.add(jobConfigurationResponse);
        }
        return response;
    }

    public static JobConfiguration map(final org.tuxdevelop.spring.batch.lightmin.api.resource.admin.JobConfiguration jobConfiguration) {
        final JobConfiguration response = new JobConfiguration();
        response.setJobName(jobConfiguration.getJobName());
        response.setJobConfigurationId(jobConfiguration.getJobConfigurationId());
        response.setJobParameters(mapToMap(jobConfiguration.getJobParameters()));
        response.setJobIncrementer(map(jobConfiguration.getJobIncrementer()));
        response.setJobSchedulerConfiguration(map(jobConfiguration.getJobSchedulerConfiguration()));
        response.setJobListenerConfiguration(map(jobConfiguration.getJobListenerConfiguration()));
        return response;
    }

    public static org.springframework.batch.core.JobParameters map(final JobParameters jobParameters) {
        final Map<String, org.springframework.batch.core.JobParameter> parametersMap = new HashMap<>();
        if (jobParameters != null) {
            for (final Map.Entry<String, JobParameter> entry : jobParameters.getParameters().entrySet()) {
                final org.springframework.batch.core.JobParameter.ParameterType parameterType = map(entry.getValue()
                        .getParameterType());
                final org.springframework.batch.core.JobParameter jobParameter;
                final String parameter = String.valueOf(entry.getValue().getParameter());
                switch (parameterType) {
                    case STRING:
                        jobParameter = new org.springframework.batch.core.JobParameter(parameter);
                        break;
                    case DOUBLE:
                        jobParameter = new org.springframework.batch.core.JobParameter(Double.parseDouble(parameter));
                        break;
                    case LONG:
                        jobParameter = new org.springframework.batch.core.JobParameter(Long.parseLong(parameter));
                        break;
                    case DATE:
                        jobParameter = new org.springframework.batch.core.JobParameter(new Date(Long.parseLong(parameter)));
                        break;
                    default:
                        throw new SpringBatchLightminApplicationException("Unknown JobParameterType: " + entry.getValue().getParameterType());
                }
                parametersMap.put(entry.getKey(), jobParameter);
            }
        }
        return new org.springframework.batch.core.JobParameters(parametersMap);
    }

    private static JobSchedulerConfiguration map(final org.tuxdevelop.spring.batch.lightmin.api.resource.admin.JobSchedulerConfiguration jobSchedulerConfiguration) {
        final JobSchedulerConfiguration response;
        if (jobSchedulerConfiguration != null) {
            response = new JobSchedulerConfiguration();
            response.setJobSchedulerType(map(jobSchedulerConfiguration.getJobSchedulerType()));
            response.setCronExpression(jobSchedulerConfiguration.getCronExpression());
            response.setFixedDelay(jobSchedulerConfiguration.getFixedDelay());
            response.setInitialDelay(jobSchedulerConfiguration.getInitialDelay());
            response.setSchedulerStatus(map(jobSchedulerConfiguration.getSchedulerStatus()));
            response.setTaskExecutorType(map(jobSchedulerConfiguration.getTaskExecutorType()));
        } else {
            response = null;
        }
        return response;
    }

    private static JobListenerConfiguration map(final org.tuxdevelop.spring.batch.lightmin.api.resource.admin.JobListenerConfiguration jobListenerConfiguration) {

        final JobListenerConfiguration response;
        if (jobListenerConfiguration != null) {
            response = new JobListenerConfiguration();
{'fraction_non_alphanumeric': 0.08736661585365854, 'fraction_numerical': 0.0005716463414634146, 'mean_word_length': 2.971623155505108, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, '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': '5137330', 'n_tokens_mistral': 2416, 'n_tokens_neox': 2345, 'n_words': 425}