Commit 111d7321 authored by Maxym Borodenko's avatar Maxym Borodenko Committed by Matija Obreza

@Valid in the Service + Impl

parent 34814653
......@@ -92,6 +92,8 @@ import com.google.common.collect.Lists;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
import javax.validation.Valid;
/**
* The Class DatasetServiceImpl.
*/
......@@ -153,7 +155,7 @@ public class DatasetServiceImpl implements DatasetService {
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#source.owner, 'write')")
public Dataset createDataset(final Dataset source) {
public Dataset createDataset(@Valid final Dataset source) {
LOG.info("Create Dataset. Input data {}", source);
final DatasetVersions datasetVersions = new DatasetVersions();
datasetVersionsRepository.save(datasetVersions);
......@@ -201,7 +203,7 @@ public class DatasetServiceImpl implements DatasetService {
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#input, 'write')")
public Dataset updateDataset(final Dataset input) {
public Dataset updateDataset(@Valid final Dataset input) {
LOG.info("Update Dataset. Input data {}", input);
final Dataset dataset = loadDataset(input);
......@@ -226,7 +228,7 @@ public class DatasetServiceImpl implements DatasetService {
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#dataset, 'write')")
public Dataset updateAccessionRefs(Dataset dataset, final Set<AccessionRef> accessionRefs) {
public Dataset updateAccessionRefs(Dataset dataset, @Valid final Set<AccessionRef> accessionRefs) {
LOG.info("Update AccessionIdentifiers. Input dataset: {}, input accessionRefs {}", dataset, accessionRefs);
dataset = loadDataset(dataset);
if (dataset.getAccessionRefs() != null && !dataset.getAccessionRefs().isEmpty()) {
......@@ -540,7 +542,7 @@ public class DatasetServiceImpl implements DatasetService {
@Transactional
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#dataset, 'write')")
public Dataset upsertAccessions(final Dataset dataset, final Set<AccessionRef> accessionRefs) throws NotFoundElement {
public Dataset upsertAccessions(final Dataset dataset, @Valid final Set<AccessionRef> accessionRefs) throws NotFoundElement {
final Dataset loadedDataset = datasetRepository.findByUuidAndVersion(dataset.getUuid(), dataset.getVersion());
if (loadedDataset == null) {
throw new NotFoundElement("Dataset doesn't exist");
......@@ -701,7 +703,7 @@ public class DatasetServiceImpl implements DatasetService {
@Transactional
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#dataset, 'write')")
public DatasetCreator createDatasetCreator(Dataset dataset, final DatasetCreator input) throws NotFoundElement {
public DatasetCreator createDatasetCreator(Dataset dataset, @Valid final DatasetCreator input) throws NotFoundElement {
dataset = loadDataset(dataset);
input.setDataset(dataset);
return datasetCreatorRepository.save(input);
......@@ -776,7 +778,7 @@ public class DatasetServiceImpl implements DatasetService {
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#dataset, 'write')")
public DatasetCreator updateDatasetCreator(final Dataset dataset, final DatasetCreator input) throws NotFoundElement {
public DatasetCreator updateDatasetCreator(final Dataset dataset, @Valid final DatasetCreator input) throws NotFoundElement {
final DatasetCreator datasetCreator = loadDatasetCreator(input);
if (!datasetCreator.getDataset().getUuid().equals(dataset.getUuid())) {
throw new InvalidApiUsageException("Creator does not belong to dataset");
......@@ -934,7 +936,7 @@ public class DatasetServiceImpl implements DatasetService {
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#dataset, 'write')")
public DatasetLocation createLocation(Dataset dataset, final DatasetLocation input) throws NotFoundElement {
public DatasetLocation createLocation(Dataset dataset, @Valid final DatasetLocation input) throws NotFoundElement {
dataset = datasetRepository.findByUuidAndVersion(dataset.getUuid(), dataset.getVersion());
LOG.info("Create DatasetLocation {} for dataset {}", input, dataset.getUuid());
input.setDataset(dataset);
......@@ -1029,7 +1031,7 @@ public class DatasetServiceImpl implements DatasetService {
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#dataset, 'write')")
public DatasetLocation updateLocation(Dataset dataset, final DatasetLocation input) throws NotFoundElement {
public DatasetLocation updateLocation(Dataset dataset, @Valid final DatasetLocation input) throws NotFoundElement {
dataset = loadDataset(dataset);
final DatasetLocation datasetLocation = loadLocation(input);
if (!datasetLocation.getDataset().getUuid().equals(dataset.getUuid())) {
......
......@@ -119,7 +119,7 @@ public class KPIServiceImpl implements KPIService {
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#dimension, 'ADMINISTRATION')")
@Override
@Transactional
public <T extends Dimension<?>> T save(T dimension) {
public <T extends Dimension<?>> T save(@Valid T dimension) {
LOG.debug("Persising dimension {}", dimension);
return lazyLoad(dimensionRepository.save(dimension));
}
......@@ -174,7 +174,7 @@ public class KPIServiceImpl implements KPIService {
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#execution, 'ADMINISTRATION')")
@Override
@Transactional
public Execution save(Execution execution) {
public Execution save(@Valid Execution execution) {
Execution target = executionRepository.findByName(execution.getName());
if (target == null) {
target = execution;
......
......@@ -70,6 +70,8 @@ import org.springframework.validation.annotation.Validated;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
import javax.validation.Valid;
/**
* The Class SubsetServiceImpl.
*
......@@ -152,7 +154,7 @@ public class SubsetServiceImpl implements SubsetService {
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#institute, 'WRITE')")
public Subset create(final FaoInstitute institute, final Subset source) {
public Subset create(final FaoInstitute institute, @Valid final Subset source) {
LOG.info("Create Subset.");
if (! StringUtils.equals(institute.getCode(), source.getWiewsCode())) {
throw new InvalidApiUsageException("Institute code of the subset does not match the code of Institute");
......@@ -401,7 +403,7 @@ public class SubsetServiceImpl implements SubsetService {
@Transactional
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#subset, 'write')")
public SubsetCreator createSubsetCreator(Subset subset, SubsetCreator input) throws NotFoundElement {
public SubsetCreator createSubsetCreator(Subset subset, @Valid SubsetCreator input) throws NotFoundElement {
subset = loadSubset(subset);
input.setSubset(subset);
return subsetCreatorRepository.save(input);
......@@ -472,7 +474,7 @@ public class SubsetServiceImpl implements SubsetService {
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#subset, 'write')")
public SubsetCreator updateSubsetCreator(Subset subset, SubsetCreator input) throws NotFoundElement {
public SubsetCreator updateSubsetCreator(Subset subset, @Valid SubsetCreator input) throws NotFoundElement {
final SubsetCreator subsetCreator = loadSubsetCreator(input);
if (!subsetCreator.getSubset().getUuid().equals(subset.getUuid())) {
throw new InvalidApiUsageException("Creator does not belong to subset");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment