Commit 7d1d0b3e authored by Matija Obreza's avatar Matija Obreza

Fix: Approve descriptors when approving datasets and descriptor lists

parent 03fb6b4c
Pipeline #7144 passed with stages
in 10 minutes 24 seconds
......@@ -49,6 +49,7 @@ import org.genesys.catalog.persistence.dataset.DatasetLocationRepository;
import org.genesys.catalog.persistence.dataset.DatasetRepository;
import org.genesys.catalog.persistence.dataset.DatasetVersionsRepository;
import org.genesys.catalog.service.DatasetService;
import org.genesys.catalog.service.DescriptorService;
import org.genesys.filerepository.InvalidRepositoryFileDataException;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFileException;
......@@ -126,6 +127,10 @@ public class DatasetServiceImpl implements DatasetService {
@Autowired
private DownloadService downloadService;
/** The descriptor service. */
@Autowired
private DescriptorService descriptorService;
/** The file repository path. */
@Value("${file.repository.datasets.folder}")
public String datasetRepositoryPath;
......@@ -505,6 +510,18 @@ public class DatasetServiceImpl implements DatasetService {
if (loaded.getState() == PublishState.DRAFT) {
throw new InvalidApiUsageException("Dataset should be sent for review before publication");
}
for (final Descriptor descriptor : loaded.getDescriptors()) {
if (descriptor.getState() != PublishState.PUBLISHED) {
LOG.info("Publishing descriptor {}", descriptor);
try {
descriptorService.approveDescriptor(descriptor);
} catch(InvalidApiUsageException e) {
throw e;
}
}
}
loaded.setState(PublishState.PUBLISHED);
......@@ -561,6 +578,19 @@ public class DatasetServiceImpl implements DatasetService {
if (loaded.getState() == PublishState.REVIEWING) {
throw new InvalidApiUsageException("The dataset is already under approval");
}
for (final Descriptor descriptor : loaded.getDescriptors()) {
if (descriptor.getState() == PublishState.DRAFT) {
LOG.info("Submitting descriptor for review {}", descriptor);
try {
descriptorService.reviewDescriptor(descriptor);
} catch(InvalidApiUsageException e) {
throw e;
}
}
}
loaded.setState(PublishState.REVIEWING);
return lazyLoad(datasetRepository.save(loaded));
......
......@@ -353,12 +353,12 @@ public class DescriptorListServiceImpl implements DescriptorListService {
}
for (final Descriptor descriptor : loaded.getDescriptors()) {
if (descriptor.getState() == PublishState.REVIEWING) {
LOG.info("Approving descriptor {}", descriptor);
if (descriptor.getState() != PublishState.PUBLISHED) {
LOG.info("Publishing descriptor {}", descriptor);
try {
descriptorService.approveDescriptor(descriptor);
} catch(InvalidApiUsageException e) {
LOG.warn(e.getMessage());
throw e;
}
}
}
......@@ -391,7 +391,7 @@ public class DescriptorListServiceImpl implements DescriptorListService {
try {
descriptorService.reviewDescriptor(descriptor);
} catch (InvalidApiUsageException e) {
LOG.warn(e.getMessage());
throw e;
}
}
}
......
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