package ca.corefacility.bioinformatics.irida.service.impl;

import ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile;
import javax.transaction.Transactional;
import javax.validation.Validator;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis;
import ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC;
import ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisOutputFile;
import ca.corefacility.bioinformatics.irida.repositories.analysis.AnalysisOutputFileRepository;
import ca.corefacility.bioinformatics.irida.repositories.analysis.AnalysisRepository;
import ca.corefacility.bioinformatics.irida.service.AnalysisService;

/**
 * Implementation of {@link AnalysisService}.
 * 
 *
 */
@Service
public class AnalysisServiceImpl extends CRUDServiceImpl<Long, Analysis> implements AnalysisService {

	private final AnalysisRepository analysisRepository;
	private final AnalysisOutputFileRepository analysisOutputFileRepository;

	@Autowired
	public AnalysisServiceImpl(AnalysisRepository analysisRepository,
			AnalysisOutputFileRepository analysisOutputFileRepository, Validator validator) {
		super(analysisRepository, validator, Analysis.class);
		this.analysisRepository = analysisRepository;
		this.analysisOutputFileRepository = analysisOutputFileRepository;
	}

	@Override
	@Transactional
	public Analysis create(Analysis analysis) {
		for (AnalysisOutputFile a : analysis.getAnalysisOutputFiles()) {
			analysisOutputFileRepository.save(a);
		}
		return analysisRepository.save(analysis);
	}
        
        
	/**
	 * {@inheritDoc}
	 */
	@Override
	public AnalysisFastQC getFastQCAnalysisForSequenceFile(final SequenceFile sequenceFile) {
		return analysisRepository.findFastqcAnalysisForSequenceFile(sequenceFile);
	}
}

@@ -126,24 +126,25 @@
 quenceFile;%0A
+%0A
 import javax
@@ -171,16 +171,47 @@
 tional;%0A
+import javax.validation.Valid;%0A
 import j
@@ -238,16 +238,16 @@
 dator;%0A%0A
-
 import o
@@ -301,16 +301,81 @@
 owired;%0A
+import org.springframework.security.access.prepost.PreAuthorize;%0A
 import o
@@ -1563,33 +1563,100 @@
 %7D%0A%0A%09
-@Override%0A%09@Transactional
+/**%0A%09 * %7B@inheritDoc%7D%0A%09 */%0A%09@Override%0A%09@Transactional%0A%09@PreAuthorize(%22hasRole('ROLE_USER')%22)
 %0A%09pu
@@ -1676,16 +1676,23 @@
  create(
+@Valid 
 Analysis

Update permissions on AnalysisServiceImpl.