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

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException;
import ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException;
import ca.corefacility.bioinformatics.irida.model.RemoteAPI;
import ca.corefacility.bioinformatics.irida.repositories.RemoteAPIRepository;
import ca.corefacility.bioinformatics.irida.service.RemoteAPIService;

/**
 * Service implementation for storing and retrieving RemoteAPI objects from a
 * {@link RemoteAPIRepository}
 * 
 *
 */
@Transactional
@Service
public class RemoteAPIServiceImpl extends CRUDServiceImpl<Long, RemoteAPI> implements RemoteAPIService {

	private RemoteAPIServiceImpl() {
		super(null, null, RemoteAPI.class);
	}

	@Autowired
	public RemoteAPIServiceImpl(RemoteAPIRepository repository, Validator validator)
			throws ConstraintViolationException, EntityExistsException {
		super(repository, validator, RemoteAPI.class);
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	@PreAuthorize("hasRole('ROLE_ADMIN')")
	public Page<RemoteAPI> search(Specification<RemoteAPI> specification, int page, int size, Direction order,
			String... sortProperties) {
		return super.search(specification, page, size, order, sortProperties);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	@PreAuthorize("hasRole('ROLE_ADMIN')")
	public void delete(Long id) throws EntityNotFoundException {
		super.delete(id);
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	@PreAuthorize("permitAll")
	public RemoteAPI read(Long id) throws EntityNotFoundException {
		return super.read(id);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	@PreAuthorize("permitAll")
	public Iterable<RemoteAPI> findAll() {
		return super.findAll();
	}

}

@@ -1523,32 +1523,204 @@
 'ROLE_ADMIN')%22)%0A
+%09public RemoteAPI create(final RemoteAPI remoteAPI) %7B%0A%09%09return super.create(remoteAPI);%0A%09%7D%0A%09%0A%09/**%0A%09 * %7B@inheritDoc%7D%0A%09 */%0A%09@Override%0A%09@PreAuthorize(%22hasRole('ROLE_ADMIN')%22)%0A
 %09public Page%3CRem

Fix permissions on remote api service