Commit 5f87f4c7 authored by Maxym Borodenko's avatar Maxym Borodenko Committed by Matija Obreza

Keep compatibility with non updated frontend clients.

parent 1e31ce42
......@@ -209,6 +209,7 @@ public class DatasetController {
return datasetService.upsertAccessions(dataset, accessionIdentifiers);
}
//FIXME Remove it as soon as frontend clients start supporting PublishState
/**
* Loads dataset by uuid and version and sets new publish state
*
......@@ -224,9 +225,9 @@ public class DatasetController {
final Dataset dataset = datasetService.loadDataset(uuid, version);
if (published) {
return datasetService.publishDataset(dataset);
return datasetService.approveDataset(dataset);
} else {
return datasetService.unpublishDataset(dataset);
return datasetService.rejectDataset(dataset);
}
}
......@@ -243,6 +244,32 @@ public class DatasetController {
return datasetService.approveDataset(dataset);
}
/**
* Loads dataset by uuid and version and send to review.
*
* @param uuid dataset UUID
* @param version record version
* @return dataset in review state
*/
@RequestMapping(value = "/for-review", method = RequestMethod.POST)
public Dataset reviewDataset(@RequestParam(value = "uuid", required = true) final UUID uuid, @RequestParam(value = "version", required = true) final int version) {
final Dataset dataset = datasetService.loadDataset(uuid, version);
return datasetService.reviewDataset(dataset);
}
/**
* Loads dataset by uuid and version and unpublish it.
*
* @param uuid dataset UUID
* @param version record version
* @return unpublished dataset
*/
@RequestMapping(value = "/reject", method = RequestMethod.POST)
public Dataset rejectDataset(@RequestParam(value = "uuid", required = true) final UUID uuid, @RequestParam(value = "version", required = true) final int version) {
final Dataset dataset = datasetService.loadDataset(uuid, version);
return datasetService.rejectDataset(dataset);
}
/**
* Adds the descriptors.
*
......
......@@ -258,9 +258,9 @@ public class DescriptorController {
final Descriptor descriptor = descriptorService.getDescriptor(uuid, version);
if (published) {
return descriptorService.publishDescriptor(descriptor);
return descriptorService.approveDescriptor(descriptor);
} else {
return descriptorService.unpublishDescriptor(descriptor);
return descriptorService.rejectDescriptor(descriptor);
}
}
......@@ -272,9 +272,35 @@ public class DescriptorController {
* @return published Descriptor (admin-only)
*/
@RequestMapping(value = "/approve", method = RequestMethod.POST)
public Descriptor approveDataset(@RequestParam(value = "uuid", required = true) final UUID uuid, @RequestParam(value = "version", required = true) final int version) {
public Descriptor approveDescriptor(@RequestParam(value = "uuid", required = true) final UUID uuid, @RequestParam(value = "version", required = true) final int version) {
final Descriptor descriptor = descriptorService.getDescriptor(uuid, version);
return descriptorService.approveDescriptor(descriptor);
}
/**
* Loads descriptor by uuid and version and send to review.
*
* @param uuid descriptor UUID
* @param version record version
* @return descriptor in review state
*/
@RequestMapping(value = "/for-review", method = RequestMethod.POST)
public Descriptor reviewDescriptor(@RequestParam(value = "uuid", required = true) final UUID uuid, @RequestParam(value = "version", required = true) final int version) {
final Descriptor descriptor = descriptorService.getDescriptor(uuid, version);
return descriptorService.reviewDescriptor(descriptor);
}
/**
* Loads descriptor by uuid and version and unpublish it.
*
* @param uuid descriptor UUID
* @param version record version
* @return unpublished descriptor
*/
@RequestMapping(value = "/reject", method = RequestMethod.POST)
public Descriptor rejectDescriptor(@RequestParam(value = "uuid", required = true) final UUID uuid, @RequestParam(value = "version", required = true) final int version) {
final Descriptor descriptor = descriptorService.getDescriptor(uuid, version);
return descriptorService.rejectDescriptor(descriptor);
}
}
......@@ -25,7 +25,6 @@ import javax.servlet.http.HttpServletResponse;
import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.api.FilteredPage;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.filters.DescriptorListFilter;
import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.model.traits.DescriptorList;
......@@ -132,9 +131,9 @@ public class DescriptorListController {
final DescriptorList descriptorList = descriptorListService.getDescriptorList(uuid, version);
if (published) {
return descriptorListService.publishDescriptorList(descriptorList);
return descriptorListService.approveDescriptorList(descriptorList);
} else {
return descriptorListService.unpublishDescriptorList(descriptorList);
return descriptorListService.rejectDescriptorList(descriptorList);
}
}
......@@ -151,6 +150,32 @@ public class DescriptorListController {
return descriptorListService.approveDescriptorList(descriptorList);
}
/**
* Loads DescriptorList by uuid and version and send to review.
*
* @param uuid descriptorList UUID
* @param version record version
* @return descriptorList in review state
*/
@RequestMapping(value = "/for-review", method = RequestMethod.POST)
public DescriptorList reviewDescriptorList(@RequestParam(value = "uuid", required = true) final UUID uuid, @RequestParam(value = "version", required = true) final int version) {
final DescriptorList descriptorList = descriptorListService.getDescriptorList(uuid, version);
return descriptorListService.reviewDescriptorList(descriptorList);
}
/**
* Loads descriptorList by uuid and version and unpublish it.
*
* @param uuid descriptorList UUID
* @param version record version
* @return unpublished descriptorList
*/
@RequestMapping(value = "/reject", method = RequestMethod.POST)
public DescriptorList rejectDescriptorList(@RequestParam(value = "uuid", required = true) final UUID uuid, @RequestParam(value = "version", required = true) final int version) {
final DescriptorList descriptorList = descriptorListService.getDescriptorList(uuid, version);
return descriptorListService.rejectDescriptorList(descriptorList);
}
/**
* Delete descriptor list.
*
......
......@@ -60,6 +60,10 @@ public class DatasetFilter extends UuidModelFilter {
/** The publish state. */
public Set<PublishState> state;
//FIXME Remove it as soon as frontend clients start supporting PublishState
/** The published. */
public Boolean published;
/** The crop. */
public Set<String> crop;
......@@ -75,6 +79,10 @@ public class DatasetFilter extends UuidModelFilter {
if (state != null && !state.isEmpty()) {
and.and(dataset.state.in(state));
}
if (published != null) {
final PublishState publishState = published ? PublishState.PUBLISHED : PublishState.DRAFT;
and.and(dataset.state.in(publishState));
}
if (title != null) {
and.and(title.buildQuery(dataset.title));
}
......
......@@ -78,6 +78,10 @@ public class DescriptorFilter extends UuidModelFilter {
/** The publish state. */
public Set<PublishState> state;
//FIXME Remove it as soon as frontend clients start supporting PublishState
/** The published. */
public Boolean published;
/** The integer only. */
public Boolean integerOnly;
......@@ -118,6 +122,10 @@ public class DescriptorFilter extends UuidModelFilter {
if (state != null && !state.isEmpty()) {
and.and(descriptorPath.state.in(state));
}
if (published != null) {
final PublishState publishState = published ? PublishState.PUBLISHED : PublishState.DRAFT;
and.and(descriptorPath.state.in(publishState));
}
if (integerOnly != null) {
and.and(descriptorPath.integerOnly.eq(integerOnly));
}
......
......@@ -57,6 +57,10 @@ public class DescriptorListFilter extends UuidModelFilter {
/** The publish state. */
public Set<PublishState> state;
//FIXME Remove it as soon as frontend clients start supporting PublishState
/** The published. */
public Boolean published;
/** The publisher. */
public Set<String> publisher;
......@@ -75,6 +79,10 @@ public class DescriptorListFilter extends UuidModelFilter {
if (state != null && !state.isEmpty()) {
and.and(descriptorList.state.in(state));
}
if (published != null) {
final PublishState publishState = published ? PublishState.PUBLISHED : PublishState.DRAFT;
and.and(descriptorList.state.in(publishState));
}
if (publisher != null && !publisher.isEmpty()) {
and.and(descriptorList.publisher.in(publisher));
}
......
......@@ -200,28 +200,30 @@ public interface DatasetService {
Dataset upsertAccessions(Dataset dataset, Set<AccessionIdentifier> accessionIdentifiers) throws NotFoundElement;
/**
* Puts the dataset into the Review state to be reviewed by admin. Admin and the user with MANAGE permission - only.
* Puts the dataset into the Review state to be reviewed by admin.
* Admin and the user with MANAGE permission - only.
*
* @param dataset the dataset
* @return dataset in REVIEWING state
*/
Dataset publishDataset(Dataset dataset);
Dataset reviewDataset(Dataset dataset);
/**
* Validates and publishes an unpublished dataset. Admin - only.
* Unpublishes published dataset.
* Admin and the user with MANAGE permission - only.
*
* @param dataset the dataset
* @return published dataset
* @return unpublished dataset
*/
Dataset approveDataset(Dataset dataset);
Dataset rejectDataset(Dataset dataset);
/**
* Un-publishes a dataset. Admin and the user with MANAGE permission - only.
* Validates and publishes an unpublished dataset. Admin - only
*
* @param dataset dataset to un-publish
* @return unpublished dataset
* @param dataset the dataset
* @return published dataset
*/
Dataset unpublishDataset(Dataset dataset);
Dataset approveDataset(Dataset dataset);
/**
* Update dataset file information.
......
......@@ -137,26 +137,27 @@ public interface DescriptorListService {
* Puts the descriptorList into the Review state to be reviewed by admin.
* Admin and the user with MANAGE permission - only.
*
* @param descriptorList the descriptor
* @return descriptor in REVIEWING state
* @param descriptorList the descriptorList
* @return descriptorList in REVIEWING state
*/
DescriptorList publishDescriptorList(DescriptorList descriptorList);
DescriptorList reviewDescriptorList(DescriptorList descriptorList);
/**
* Validates and publishes an unpublished descriptorList. Admin - only.
* Unpublishes published descriptorList.
* Admin and the user with MANAGE permission - only.
*
* @param descriptorList the descriptorList
* @return published descriptorList
* @return unpublished descriptorList
*/
DescriptorList approveDescriptorList(DescriptorList descriptorList);
DescriptorList rejectDescriptorList(DescriptorList descriptorList);
/**
* Un-publish a published descriptor list. Admin and the user with MANAGE permission - only.
* Validates and publishes an unpublished descriptorList. Admin - only
*
* @param descriptorList list to unpublish
* @return unpublished descriptor list
* @param descriptorList the descriptorList
* @return published descriptorList
*/
DescriptorList unpublishDescriptorList(DescriptorList descriptorList);
DescriptorList approveDescriptorList(DescriptorList descriptorList);
/**
* Completely update the descriptor list (including order).
......
......@@ -111,29 +111,30 @@ public interface DescriptorService {
List<Descriptor> upsertDescriptors(List<Descriptor> source);
/**
* Puts the descriptor into the Review state to be reviewed by admin.
* Admin and the user with MANAGE permission - only.
* Validates and publishes an unpublished descriptor. Admin - only.
*
* @param descriptor the descriptor
* @return descriptor in REVIEWING state
* @return published descriptor
*/
Descriptor publishDescriptor(Descriptor descriptor);
Descriptor approveDescriptor(Descriptor descriptor);
/**
* Validates and publishes an unpublished descriptor. Admin - only.
* Puts the descriptor into the Review state to be reviewed by admin.
* Admin and the user with MANAGE permission - only.
*
* @param descriptor the descriptor
* @return published descriptor
* @return descriptor in REVIEWING state
*/
Descriptor approveDescriptor(Descriptor descriptor);
Descriptor reviewDescriptor(Descriptor descriptor);
/**
* Un-publish a published descriptor. Admin and the user with MANAGE permission - only.
* Unpublishes published descriptor.
* Admin and the user with MANAGE permission - only.
*
* @param descriptor the descriptor
* @return unpublished descriptor
*/
Descriptor unpublishDescriptor(Descriptor descriptor);
Descriptor rejectDescriptor(Descriptor descriptor);
/**
* Gets the descriptor lists using specified descriptor.
......
......@@ -430,8 +430,9 @@ public class DatasetServiceImpl implements DatasetService {
*/
@Override
@Transactional
// FIXME Should be only for admins. Fix after frontend clients start supporting PublishState
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#dataset, 'write')")
public Dataset publishDataset(final Dataset dataset) {
public Dataset approveDataset(final Dataset dataset) {
final Dataset loaded = datasetRepository.findByUuidAndVersion(dataset.getUuid(), dataset.getVersion());
if (loaded == null) {
throw new NotFoundElement("No dataset with specified uuid and version");
......@@ -439,11 +440,21 @@ public class DatasetServiceImpl implements DatasetService {
if (loaded.isPublished()) {
throw new InvalidApiUsageException("Dataset is already published");
}
if (loaded.getState() == PublishState.REVIEWING) {
throw new InvalidApiUsageException("The dataset is already under approval");
}
loaded.setState(PublishState.REVIEWING);
// FIXME Uncomment it as soon as frontend clients start supporting PublishState
// if (loaded.getState() == PublishState.DRAFT) {
// throw new InvalidApiUsageException("Dataset should be sent for review before publication");
// }
loaded.setState(PublishState.PUBLISHED);
{
// Relax permissions on dataset files: allow USERS and ANONYMOUS to read the
// files
for (final RepositoryFile datasetFile : loaded.getRepositoryFiles()) {
aclService.makePubliclyReadable(datasetFile, true);
}
}
return lazyLoad(datasetRepository.save(loaded));
}
......@@ -453,8 +464,8 @@ public class DatasetServiceImpl implements DatasetService {
*/
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR')")
public Dataset approveDataset(final Dataset dataset) {
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#dataset, 'write')")
public Dataset reviewDataset(final Dataset dataset) {
final Dataset loaded = datasetRepository.findByUuidAndVersion(dataset.getUuid(), dataset.getVersion());
if (loaded == null) {
throw new NotFoundElement("No dataset with specified uuid and version");
......@@ -462,24 +473,10 @@ public class DatasetServiceImpl implements DatasetService {
if (loaded.isPublished()) {
throw new InvalidApiUsageException("Dataset is already published");
}
if (loaded.getState() == PublishState.DRAFT) {
throw new InvalidApiUsageException("Dataset should be sent for review before publication");
}
// Map<String, String> errorMap = loaded.validation();
//
// if (!errorMap.isEmpty())
// throw new PublishValidationException(errorMap);
loaded.setState(PublishState.PUBLISHED);
{
// Relax permissions on dataset files: allow USERS and ANONYMOUS to read the
// files
for (final RepositoryFile datasetFile : loaded.getRepositoryFiles()) {
aclService.makePubliclyReadable(datasetFile, true);
}
if (loaded.getState() == PublishState.REVIEWING) {
throw new InvalidApiUsageException("The dataset is already under approval");
}
loaded.setState(PublishState.REVIEWING);
return lazyLoad(datasetRepository.save(loaded));
}
......@@ -490,7 +487,7 @@ public class DatasetServiceImpl implements DatasetService {
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#dataset, 'administration')")
public Dataset unpublishDataset(final Dataset dataset) {
public Dataset rejectDataset(final Dataset dataset) {
final Dataset loaded = datasetRepository.findByUuidAndVersion(dataset.getUuid(), dataset.getVersion());
if (loaded == null) {
throw new NotFoundElement("No dataset with specified uuid and version");
......
......@@ -330,8 +330,9 @@ public class DescriptorListServiceImpl implements DescriptorListService {
*/
@Override
@Transactional
// FIXME Should be only for admins. Fix after frontend clients start supporting PublishState
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#descriptorList, 'WRITE')")
public DescriptorList publishDescriptorList(final DescriptorList descriptorList) {
public DescriptorList approveDescriptorList(final DescriptorList descriptorList) {
final DescriptorList loaded = descriptorListRepository.findByUuidAndVersion(descriptorList.getUuid(), descriptorList.getVersion());
if (loaded == null) {
throw new NotFoundElement("No DescriptorList with specified uuid and version");
......@@ -339,18 +340,23 @@ public class DescriptorListServiceImpl implements DescriptorListService {
if (loaded.isPublished()) {
throw new InvalidApiUsageException("Descriptor List is already published");
}
if (loaded.getState() == PublishState.REVIEWING) {
throw new InvalidApiUsageException("The Descriptor List is already under approval");
}
// FIXME Uncomment it as soon as frontend clients start supporting PublishState
// if (loaded.getState() == PublishState.DRAFT) {
// throw new InvalidApiUsageException("Descriptor List should be sent for review before publication");
// }
for (final Descriptor descriptor : loaded.getDescriptors()) {
if (descriptor.getState() == PublishState.DRAFT) {
LOG.info("Send to review descriptor {}", descriptor);
descriptorService.publishDescriptor(descriptor);
if (descriptor.getState() == PublishState.REVIEWING) {
LOG.info("Approving descriptor {}", descriptor);
try {
descriptorService.approveDescriptor(descriptor);
} catch(InvalidApiUsageException e) {
LOG.warn(e.getMessage());
}
}
}
loaded.setState(PublishState.REVIEWING);
loaded.setState(PublishState.PUBLISHED);
return lazyLoad(descriptorListRepository.save(loaded));
}
......@@ -359,27 +365,31 @@ public class DescriptorListServiceImpl implements DescriptorListService {
*/
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR')")
public DescriptorList approveDescriptorList(final DescriptorList descriptorList) {
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#descriptorList, 'WRITE')")
public DescriptorList reviewDescriptorList(final DescriptorList descriptorList) {
final DescriptorList loaded = descriptorListRepository.findByUuidAndVersion(descriptorList.getUuid(), descriptorList.getVersion());
if (loaded == null) {
throw new NotFoundElement("No DescriptorList with specified uuid and version");
}
if (loaded.isPublished()) {
throw new InvalidApiUsageException("Descriptor List is already published");
throw new InvalidApiUsageException("DescriptorList is already published");
}
if (loaded.getState() == PublishState.DRAFT) {
throw new InvalidApiUsageException("Descriptor List should be sent for review before publication");
if (loaded.getState() == PublishState.REVIEWING) {
throw new InvalidApiUsageException("The DescriptorList is already under approval");
}
for (final Descriptor descriptor : loaded.getDescriptors()) {
if (descriptor.getState() == PublishState.REVIEWING) {
LOG.info("Approving descriptor {}", descriptor);
descriptorService.approveDescriptor(descriptor);
if (descriptor.getState() == PublishState.DRAFT) {
LOG.info("Send to review descriptor {}", descriptor);
try {
descriptorService.reviewDescriptor(descriptor);
} catch (InvalidApiUsageException e) {
LOG.warn(e.getMessage());
}
}
}
loaded.setState(PublishState.PUBLISHED);
loaded.setState(PublishState.REVIEWING);
return lazyLoad(descriptorListRepository.save(loaded));
}
......@@ -389,7 +399,7 @@ public class DescriptorListServiceImpl implements DescriptorListService {
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#descriptorList, 'administration')")
public DescriptorList unpublishDescriptorList(final DescriptorList descriptorList) {
public DescriptorList rejectDescriptorList(final DescriptorList descriptorList) {
final DescriptorList loaded = descriptorListRepository.findByUuidAndVersion(descriptorList.getUuid(), descriptorList.getVersion());
if (loaded == null) {
throw new NotFoundElement("No DescriptorList with specified uuid and version");
......
......@@ -305,13 +305,14 @@ public class DescriptorServiceImpl implements DescriptorService {
/*
* (non-Javadoc)
* @see
* org.genesys.catalog.service.DescriptorService#publishDescriptor(org.genesys.
* org.genesys.catalog.service.DescriptorService#approveDescriptor(org.genesys.
* catalog.model.traits.Descriptor)
*/
@Override
@Transactional
// FIXME Should be only for admins. Fix after frontend clients start supporting PublishState
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#descriptor, 'WRITE')")
public Descriptor publishDescriptor(final Descriptor descriptor) {
public Descriptor approveDescriptor(final Descriptor descriptor) {
final Descriptor loaded = descriptorRepository.findByUuidAndVersion(descriptor.getUuid(), descriptor.getVersion());
if (loaded == null) {
throw new NotFoundElement("No Descriptor with specified uuid and version");
......@@ -319,25 +320,25 @@ public class DescriptorServiceImpl implements DescriptorService {
if (loaded.isPublished()) {
throw new InvalidApiUsageException("Descriptor is already published");
}
if (loaded.getState() == PublishState.REVIEWING) {
throw new InvalidApiUsageException("The Descriptor is already under approval");
}
// FIXME Uncomment it as soon as frontend clients start supporting PublishState
// if (loaded.getState() == PublishState.DRAFT) {
// throw new InvalidApiUsageException("Descriptor should be sent for review before publication");
// }
loaded.setState(PublishState.REVIEWING);
loaded.setState(PublishState.PUBLISHED);
return lazyLoad(descriptorRepository.save(loaded));
}
/*
* (non-Javadoc)
* @see
* org.genesys.catalog.service.DescriptorService#approveDescriptor(org.genesys.
* catalog.model.traits.Descriptor)
* org.genesys.catalog.service.DescriptorService#reviewDescriptor(org.genesys
* .catalog.model.traits.Descriptor)
*/
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR')")
public Descriptor approveDescriptor(final Descriptor descriptor) {
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#descriptor, 'administration')")
public Descriptor reviewDescriptor(final Descriptor descriptor) {
final Descriptor loaded = descriptorRepository.findByUuidAndVersion(descriptor.getUuid(), descriptor.getVersion());
if (loaded == null) {
throw new NotFoundElement("No Descriptor with specified uuid and version");
......@@ -345,24 +346,25 @@ public class DescriptorServiceImpl implements DescriptorService {
if (loaded.isPublished()) {
throw new InvalidApiUsageException("Descriptor is already published");
}
if (loaded.getState() == PublishState.DRAFT) {
throw new InvalidApiUsageException("Descriptor should be sent for review before publication");
if (loaded.getState() == PublishState.REVIEWING) {
throw new InvalidApiUsageException("The Descriptor is already under approval");
}
loaded.setState(PublishState.PUBLISHED);
loaded.setState(PublishState.REVIEWING);