<commit_before>package ca.corefacility.bioinformatics.irida.service.impl.analysis.sample;

import java.util.Collection;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssemblyFromAnalysis;
import ca.corefacility.bioinformatics.irida.model.sample.Sample;
import ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis;
import ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisAssemblyAnnotation;
import ca.corefacility.bioinformatics.irida.repositories.sample.SampleRepository;
import ca.corefacility.bioinformatics.irida.service.analysis.sample.AnalysisSampleUpdatorService;

/**
 * Updates a sample with the results from a genome assembly.
 */
@Service
public class AssemblySampleUpdatorService implements AnalysisSampleUpdatorService {

	private static final Logger logger = LoggerFactory.getLogger(AssemblySampleUpdatorService.class);

	private final SampleRepository sampleRepository;

	@Autowired
	public AssemblySampleUpdatorService(SampleRepository sampleRepository) {
		this.sampleRepository = sampleRepository;
	}

	@Override
	public void update(Collection<Sample> samples, Analysis analysis) {
		if (samples.size() != 1) {
			throw new RuntimeException("Error: expected only 1 sample, but got " + samples.size() + " samples");
		}

		Sample sample = samples.iterator().next();

		if (sample.getAssembly() == null) {
			sample.setGenomeAssembly(new GenomeAssemblyFromAnalysis((AnalysisAssemblyAnnotation) analysis));
			sampleRepository.save(sample);<commit_msg>Added security checks<commit_after>package ca.corefacility.bioinformatics.irida.service.impl.analysis.sample;

import java.util.Collection;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;

import ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssemblyFromAnalysis;
import ca.corefacility.bioinformatics.irida.model.sample.Sample;
import ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis;
import ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisAssemblyAnnotation;
import ca.corefacility.bioinformatics.irida.repositories.sample.SampleRepository;
import ca.corefacility.bioinformatics.irida.service.analysis.sample.AnalysisSampleUpdatorService;

/**
 * Updates a sample with the results from a genome assembly.
 */
@Service
public class AssemblySampleUpdatorService implements AnalysisSampleUpdatorService {

	private static final Logger logger = LoggerFactory.getLogger(AssemblySampleUpdatorService.class);

	private final SampleRepository sampleRepository;

	@Autowired
	public AssemblySampleUpdatorService(SampleRepository sampleRepository) {
		this.sampleRepository = sampleRepository;
	}

	@Override
	@PreAuthorize("hasPermission(#samples, 'canUpdateSample')")
	public void update(Collection<Sample> samples, Analysis analysis) {
		if (samples.size() != 1) {
			throw new RuntimeException("Error: expected only 1 sample, but got " + samples.size() + " samples");
		}

		Sample sample = samples.iterator().next();

		if (sample.getAssembly() == null) {
			sample.setGenomeAssembly(new GenomeAssemblyFromAnalysis((AnalysisAssemblyAnnotation) analysis));
			sampleRepository.save(sample);
{'fraction_non_alphanumeric': 0.09414106939704209, 'fraction_numerical': 0.0022753128555176336, 'mean_word_length': 6.903370786516854, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2411136', 'n_tokens_mistral': 1009, 'n_tokens_neox': 943, 'n_words': 179}