<commit_before>package edu.virginia.psyc.templeton.service;

import edu.virginia.psyc.templeton.domain.TempletonParticipant;
import edu.virginia.psyc.templeton.domain.TempletonStudy;
import edu.virginia.psyc.templeton.persistence.TempletonParticipantRepository;
import org.mindtrails.domain.Participant;
import org.mindtrails.service.ParticipantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.security.Principal;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;

/**
 * Largely a wrapper around the Participant Repository.  Allows us to
 * save, create, and find customized participant objects.
 */
@Service
public class TempletonParticipantService implements ParticipantService {

    protected static final Random RANDOM = new Random();  // For generating random CBM and Prime values.

    @Autowired
    TempletonParticipantRepository repository;

    List<TempletonParticipant.CONDITION> CONDITION_VALUES =
            Collections.unmodifiableList(Arrays.asList(TempletonParticipant.CONDITION.values()));
    List<TempletonParticipant.PRIME> PRIME_VALUES =
            Collections.unmodifiableList(Arrays.asList(TempletonParticipant.PRIME.values()));

    @Override
    public Participant create() {
        TempletonParticipant p = new TempletonParticipant();
        p.setPrime(PRIME_VALUES.get(RANDOM.nextInt(PRIME_VALUES.size())));
        p.setConditioning(CONDITION_VALUES.get(RANDOM.nextInt(CONDITION_VALUES.size())));

        p.setStudy(new TempletonStudy());
        return p;
    }

    @Override
    public Participant get(Principal p) {
        return repository.findByEmail(p.getName());
    }

    @Override
    public Participant findByEmail(String email) {
        return repository.findByEmail(email);
    }

    @Override
    public Participant findOne(long id) { return repository.findOne(id); };

    @Override
    public Page findAll(PageRequest pageRequest) {return repository.findAll(pageRequest);}

    @Override
    public Page search(String search, PageRequest pageRequest) {
        return repository.search(search, pageRequest);
    }

    @Override
    public void saveNew(Participant p, HttpSession session) {
        save(p);
    }

    @Override
    public void save(Participant p) {

        if(p instanceof TempletonParticipant) {
            repository.save((TempletonParticipant)p);
        } else {
            throw new IllegalArgumentException("Participant must be a Templeton participant.");
        }
    }

    @Override
    public void flush() {
        repository.flush();
    }

    @Override
    public long count() {
        return repository.count();
    }
}<commit_msg>Fixing a bug I introduced that would prevent the site from working correctly.<commit_after>package edu.virginia.psyc.templeton.service;

import edu.virginia.psyc.templeton.domain.TempletonParticipant;
import edu.virginia.psyc.templeton.domain.TempletonStudy;
import edu.virginia.psyc.templeton.persistence.TempletonParticipantRepository;
import org.mindtrails.domain.Participant;
import org.mindtrails.service.ParticipantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.security.Principal;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;

/**
 * Largely a wrapper around the Participant Repository.  Allows us to
 * save, create, and find customized participant objects.
 */
@Service
public class TempletonParticipantService implements ParticipantService {

    protected static final Random RANDOM = new Random();  // For generating random CBM and Prime values.

    @Autowired
    TempletonParticipantRepository repository;

    List<TempletonParticipant.CONDITION> CONDITION_VALUES =
            Collections.unmodifiableList(Arrays.asList(TempletonParticipant.CONDITION.values()));
    List<TempletonParticipant.PRIME> PRIME_VALUES =
            Collections.unmodifiableList(Arrays.asList(TempletonParticipant.PRIME.values()));

    @Override
    public Participant create() {
        TempletonParticipant p = new TempletonParticipant();
        p.setPrime(PRIME_VALUES.get(RANDOM.nextInt(PRIME_VALUES.size())));
        p.setConditioning(CONDITION_VALUES.get(RANDOM.nextInt(CONDITION_VALUES.size())));

        p.setStudy(new TempletonStudy());
        return p;
    }

    @Override
    public Participant get(Principal p) {
        return repository.findByEmail(p.getName());
    }

    @Override
    public Participant findByEmail(String email) {
        return repository.findByEmail(email);
    }

    @Override
    public void saveNew(Participant p, HttpSession session) {
        save(p);
    }

    @Override
    public void save(Participant p) {

        if(p instanceof TempletonParticipant) {
            repository.save((TempletonParticipant)p);
        } else {
            throw new IllegalArgumentException("Participant must be a Templeton participant.");
        }
    }

    @Override
    public void flush() {
        repository.flush();
    }

    @Override
    public long count() {
        return repository.count();
    }
}
{'fraction_non_alphanumeric': 0.09201548958141251, 'fraction_numerical': 0.0, 'mean_word_length': 3.7578947368421054, 'pattern_counts': {'":': 0, '<': 7, '<?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': '7064329', 'n_tokens_mistral': 1594, 'n_tokens_neox': 1523, 'n_words': 318}