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