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

import java.util.List;

import javax.validation.ConstraintViolationException;
import javax.validation.Valid;
import javax.validation.Validator;

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

import ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException;
import ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException;
import ca.corefacility.bioinformatics.irida.model.project.Project;
import ca.corefacility.bioinformatics.irida.model.remote.RemoteRelatedProject;
import ca.corefacility.bioinformatics.irida.repositories.RemoteRelatedProjectRepository;
import ca.corefacility.bioinformatics.irida.service.RemoteRelatedProjectService;

/**
 * Implementation of service for managing {@link RemoteRelatedProject}s
 * 
 *
 */
@Service
public class RemoteRelatedProjectServiceImpl extends CRUDServiceImpl<Long, RemoteRelatedProject> implements
		RemoteRelatedProjectService {

	RemoteRelatedProjectRepository repository;

	@Autowired
	public RemoteRelatedProjectServiceImpl(RemoteRelatedProjectRepository repository, Validator validator) {
		super(repository, validator, RemoteRelatedProject.class);
		this.repository = repository;
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	@PreAuthorize("hasRole('ROLE_USER')")
	public RemoteRelatedProject create(@Valid RemoteRelatedProject object) throws EntityExistsException, ConstraintViolationException {
		return super.create(object);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	@PreAuthorize("hasRole('ROLE_ADMIN') or hasPermission(#project, 'canReadProject')")
	public List<RemoteRelatedProject> getRemoteProjectsForProject(Project project) {
		return repository.getRemoteRelatedProjectsForProject(project);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	@PreAuthorize("hasRole('ROLE_ADMIN') or hasPermission(#project, 'canReadProject')")
	public RemoteRelatedProject getRemoteRelatedProjectForProjectAndURI(Project project, String remoteProjectURI) {
		RemoteRelatedProject remoteRelatedProjectForProjectAndURI = repository.getRemoteRelatedProjectForProjectAndURI(
				project, remoteProjectURI);
		if (remoteRelatedProjectForProjectAndURI == null) {
			throw new EntityNotFoundException("No RemoteRelatedProject exists for this project and URI");
		}
		return remoteRelatedProjectForProjectAndURI;
	}

}<commit_msg>added permission<commit_after>package ca.corefacility.bioinformatics.irida.service.impl;

import java.util.List;

import javax.validation.ConstraintViolationException;
import javax.validation.Valid;
import javax.validation.Validator;

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

import ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException;
import ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException;
import ca.corefacility.bioinformatics.irida.model.project.Project;
import ca.corefacility.bioinformatics.irida.model.remote.RemoteRelatedProject;
import ca.corefacility.bioinformatics.irida.repositories.RemoteRelatedProjectRepository;
import ca.corefacility.bioinformatics.irida.service.RemoteRelatedProjectService;

/**
 * Implementation of service for managing {@link RemoteRelatedProject}s
 * 
 *
 */
@Service
public class RemoteRelatedProjectServiceImpl extends CRUDServiceImpl<Long, RemoteRelatedProject> implements
		RemoteRelatedProjectService {

	RemoteRelatedProjectRepository repository;

	@Autowired
	public RemoteRelatedProjectServiceImpl(RemoteRelatedProjectRepository repository, Validator validator) {
		super(repository, validator, RemoteRelatedProject.class);
		this.repository = repository;
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	@PreAuthorize("hasRole('ROLE_USER')")
	public RemoteRelatedProject create(@Valid RemoteRelatedProject object) throws EntityExistsException, ConstraintViolationException {
		return super.create(object);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	@PreAuthorize("hasRole('ROLE_ADMIN') or hasPermission(#project, 'canReadProject')")
	public List<RemoteRelatedProject> getRemoteProjectsForProject(Project project) {
		return repository.getRemoteRelatedProjectsForProject(project);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	@PreAuthorize("hasRole('ROLE_ADMIN') or hasPermission(#project, 'canReadProject')")
	public RemoteRelatedProject getRemoteRelatedProjectForProjectAndURI(Project project, String remoteProjectURI) {
		RemoteRelatedProject remoteRelatedProjectForProjectAndURI = repository.getRemoteRelatedProjectForProjectAndURI(
				project, remoteProjectURI);
		if (remoteRelatedProjectForProjectAndURI == null) {
			throw new EntityNotFoundException("No RemoteRelatedProject exists for this project and URI");
		}
		return remoteRelatedProjectForProjectAndURI;
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	@PreAuthorize("hasPermission(#project, 'canReadProject')")
	public RemoteRelatedProject read(Long id) throws EntityNotFoundException {
		return super.read(id);
	}

}
{'fraction_non_alphanumeric': 0.09036608863198459, 'fraction_numerical': 0.0, 'mean_word_length': 7.551894563426688, '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': '3962309', 'n_tokens_mistral': 1504, 'n_tokens_neox': 1373, 'n_words': 241}