Commit 1e31ce42 authored by Maxym Borodenko's avatar Maxym Borodenko Committed by Matija Obreza

Publishing things

parent d0f4c654
......@@ -146,9 +146,9 @@ public class DatasetController {
*/
@PostMapping(value = "/list/{filterCode}")
public FilteredPage<Dataset> datasetListShort(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
@RequestParam(name = "l", required = false, defaultValue = "50") final int pageSize,
@RequestParam(name = "d", required = false, defaultValue = "ASC") final Sort.Direction direction,
@RequestParam(name = "s", required = false, defaultValue = "id") final String[] sort, @PathVariable("filterCode") final String filterCode) throws IOException {
@RequestParam(name = "l", required = false, defaultValue = "50") final int pageSize,
@RequestParam(name = "d", required = false, defaultValue = "ASC") final Sort.Direction direction,
@RequestParam(name = "s", required = false, defaultValue = "id") final String[] sort, @PathVariable("filterCode") final String filterCode) throws IOException {
final DatasetFilter filter = shortFilterService.filterByCode(filterCode, DatasetFilter.class);
return new FilteredPage<>(filterCode, filter, datasetService.listDatasets(filter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort)));
......@@ -204,22 +204,22 @@ public class DatasetController {
*/
@PostMapping(value = "/upsertaccessions/{UUID},{version}")
public Dataset upsertAccessions(@PathVariable("UUID") final UUID uuid, @PathVariable("version") final int version,
@RequestBody final Set<AccessionIdentifier> accessionIdentifiers) throws NotFoundElement {
@RequestBody final Set<AccessionIdentifier> accessionIdentifiers) throws NotFoundElement {
final Dataset dataset = datasetService.loadDataset(uuid, version);
return datasetService.upsertAccessions(dataset, accessionIdentifiers);
}
/**
* Loads dataset by uuid and version and tries to publish it.
* Loads dataset by uuid and version and sets new publish state
*
* @param uuid dataset UUID
* @param version record version
* @param published (admin-only) set's the published flag to specified value
* @param published sends to the review step or unpublish
* @return published Dataset
*/
@RequestMapping(value = "/publish", method = RequestMethod.POST)
public Dataset publishDataset(@RequestParam(value = "uuid", required = true) final UUID uuid, @RequestParam(value = "version", required = true) final int version,
@RequestParam(name = "published", required = false, defaultValue = "true") final boolean published) {
@RequestParam(name = "published", required = false, defaultValue = "true") final boolean published) {
final Dataset dataset = datasetService.loadDataset(uuid, version);
......@@ -230,6 +230,19 @@ public class DatasetController {
}
}
/**
* Loads dataset by uuid and version and tries to publish it.
*
* @param uuid dataset UUID
* @param version record version
* @return published Dataset (admin-only)
*/
@RequestMapping(value = "/approve", method = RequestMethod.POST)
public Dataset approveDataset(@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.approveDataset(dataset);
}
/**
* Adds the descriptors.
*
......
......@@ -117,11 +117,11 @@ public class DescriptorController {
*/
@PostMapping(value = "/list")
public FilteredPage<Descriptor> listDescriptors(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
@RequestParam(name = "l", required = false, defaultValue = "50") final int pageSize,
@RequestParam(name = "d", required = false, defaultValue = "ASC") final Sort.Direction direction,
@RequestParam(name = "s", required = false, defaultValue = "id") final String[] sort,
@RequestParam(name = "f", required = false) String filterCode,
@RequestBody(required = false) DescriptorFilter filter) throws IOException {
@RequestParam(name = "l", required = false, defaultValue = "50") final int pageSize,
@RequestParam(name = "d", required = false, defaultValue = "ASC") final Sort.Direction direction,
@RequestParam(name = "s", required = false, defaultValue = "id") final String[] sort,
@RequestParam(name = "f", required = false) String filterCode,
@RequestBody(required = false) DescriptorFilter filter) throws IOException {
if (filterCode != null) {
filter = shortFilterService.filterByCode(filterCode, DescriptorFilter.class);
......@@ -145,9 +145,9 @@ public class DescriptorController {
*/
@PostMapping(value = "/list/{filterCode}")
public FilteredPage<Descriptor> listDescriptorsByShort(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
@RequestParam(name = "l", required = false, defaultValue = "50") final int pageSize,
@RequestParam(name = "d", required = false, defaultValue = "ASC") final Sort.Direction direction,
@RequestParam(name = "s", required = false, defaultValue = "id") final String[] sort, @PathVariable("filterCode") final String filterCode) throws IOException {
@RequestParam(name = "l", required = false, defaultValue = "50") final int pageSize,
@RequestParam(name = "d", required = false, defaultValue = "ASC") final Sort.Direction direction,
@RequestParam(name = "s", required = false, defaultValue = "id") final String[] sort, @PathVariable("filterCode") final String filterCode) throws IOException {
final DescriptorFilter filter = shortFilterService.filterByCode(filterCode, DescriptorFilter.class);
return new FilteredPage<>(filterCode, filter, descriptorService.listDescriptors(filter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort)));
......@@ -244,16 +244,16 @@ public class DescriptorController {
}
/**
* Loads descriptor by uuid and version and tries to publish it.
* Loads descriptor by uuid and version and sets new publish state
*
* @param uuid descriptor UUID
* @param version record version
* @param published (admin-only) set's the published flag to specified value
* @param published sends to the review step or unpublish
* @return published Descriptor
*/
@RequestMapping(value = "/publish", method = RequestMethod.POST)
public Descriptor publishDescriptor(@RequestParam(value = "uuid", required = true) final UUID uuid, @RequestParam(value = "version", required = true) final int version,
@RequestParam(name = "published", required = false, defaultValue = "true") final boolean published) {
@RequestParam(name = "published", required = false, defaultValue = "true") final boolean published) {
final Descriptor descriptor = descriptorService.getDescriptor(uuid, version);
......@@ -264,4 +264,17 @@ public class DescriptorController {
}
}
/**
* Loads descriptor by uuid and version and tries to publish it.
*
* @param uuid descriptor UUID
* @param version record version
* @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) {
final Descriptor descriptor = descriptorService.getDescriptor(uuid, version);
return descriptorService.approveDescriptor(descriptor);
}
}
......@@ -25,6 +25,7 @@ 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;
......@@ -117,16 +118,16 @@ public class DescriptorListController {
}
/**
* Loads descriptor by uuid and version and tries to publish it.
* Loads descriptorList by uuid and version and sets new publish state
*
* @param uuid descriptor UUID
* @param uuid descriptorList UUID
* @param version record version
* @param published (admin-only) set's the published flag to specified value
* @return published Descriptor
* @param published sends to the review step or unpublish
* @return published DescriptorList
*/
@RequestMapping(value = "/publish", method = RequestMethod.POST)
public DescriptorList publishDescriptorList(@RequestParam(value = "uuid", required = true) final UUID uuid, @RequestParam(value = "version", required = true) final int version,
@RequestParam(name = "published", required = false, defaultValue = "true") final boolean published) {
@RequestParam(name = "published", required = false, defaultValue = "true") final boolean published) {
final DescriptorList descriptorList = descriptorListService.getDescriptorList(uuid, version);
......@@ -137,6 +138,19 @@ public class DescriptorListController {
}
}
/**
* Loads DescriptorList by uuid and version and tries to publish it.
*
* @param uuid descriptorList UUID
* @param version record version
* @return published DescriptorList (admin-only)
*/
@RequestMapping(value = "/approve", method = RequestMethod.POST)
public DescriptorList approveDescriptorList(@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.approveDescriptorList(descriptorList);
}
/**
* Delete descriptor list.
*
......@@ -241,9 +255,9 @@ public class DescriptorListController {
*/
@PostMapping(value = "/list/{filterCode}")
public FilteredPage<DescriptorList> listDescriptorListsByCode(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
@RequestParam(name = "l", required = false, defaultValue = "50") final int pageSize,
@RequestParam(name = "d", required = false, defaultValue = "ASC") final Sort.Direction direction,
@RequestParam(name = "s", required = false, defaultValue = "id") final String[] sort, @PathVariable("filterCode") final String filterCode) throws IOException {
@RequestParam(name = "l", required = false, defaultValue = "50") final int pageSize,
@RequestParam(name = "d", required = false, defaultValue = "ASC") final Sort.Direction direction,
@RequestParam(name = "s", required = false, defaultValue = "id") final String[] sort, @PathVariable("filterCode") final String filterCode) throws IOException {
final DescriptorListFilter filter = shortFilterService.filterByCode(filterCode, DescriptorListFilter.class);
return new FilteredPage<>(filterCode, filter, descriptorListService.listDescriptorLists(filter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort)));
......
......@@ -28,6 +28,7 @@ import org.genesys.catalog.model.Partner;
import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.service.PublishValidationInterface;
import org.genesys.filerepository.model.RepositoryFile;
import org.genesys2.server.model.PublishState;
import org.genesys2.util.MCPDUtil;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
......@@ -176,8 +177,9 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
@Column(nullable = true, length = 200)
private String created;
/** The published. */
private boolean published = false;
/** The publish state. */
@Enumerated(EnumType.ORDINAL)
private PublishState state = PublishState.DRAFT;
/**
* Preupdate.
......@@ -464,22 +466,31 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
this.created = created;
}
/*
* (non-Javadoc)
* @see org.genesys.blocks.model.Publishable#isPublished()
/**
* Gets the state.
*
* @return the state
*/
@Override
public boolean isPublished() {
return this.published;
public PublishState getState() {
return state;
}
/**
* Sets the published.
* Sets the publish state.
*
* @param published the published to set
* @param state the new publish state
*/
public void setPublished(final boolean published) {
this.published = published;
public void setState(final PublishState state) {
this.state = state;
}
/*
* (non-Javadoc)
* @see org.genesys.blocks.model.Publishable#isPublished()
*/
@Override
public boolean isPublished() {
return this.state == PublishState.PUBLISHED;
}
/**
......
......@@ -27,6 +27,7 @@ import org.genesys.blocks.model.filters.UuidModelFilter;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
import org.genesys2.server.model.PublishState;
/**
* The Class DatasetFilter.
......@@ -56,8 +57,8 @@ public class DatasetFilter extends UuidModelFilter {
/** The language. */
public Set<String> language;
/** The published. */
public Boolean published;
/** The publish state. */
public Set<PublishState> state;
/** The crop. */
public Set<String> crop;
......@@ -71,8 +72,8 @@ public class DatasetFilter extends UuidModelFilter {
final BooleanBuilder and = new BooleanBuilder();
super.buildQuery(dataset._super, and);
if (published != null) {
and.and(dataset.published.eq(published));
if (state != null && !state.isEmpty()) {
and.and(dataset.state.in(state));
}
if (title != null) {
and.and(title.buildQuery(dataset.title));
......
......@@ -32,6 +32,7 @@ import org.genesys.catalog.model.traits.QDescriptorList;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
import com.querydsl.jpa.JPAExpressions;
import org.genesys2.server.model.PublishState;
/**
* The Class DescriptorFilter.
......@@ -74,8 +75,8 @@ public class DescriptorFilter extends UuidModelFilter {
/** The publisher. */
public Set<String> publisher;
/** The published. */
public Boolean published;
/** The publish state. */
public Set<PublishState> state;
/** The integer only. */
public Boolean integerOnly;
......@@ -114,8 +115,8 @@ public class DescriptorFilter extends UuidModelFilter {
if (publisher != null && !publisher.isEmpty()) {
and.and(descriptorPath.publisher.in(publisher));
}
if (published != null) {
and.and(descriptorPath.published.eq(published));
if (state != null && !state.isEmpty()) {
and.and(descriptorPath.state.in(state));
}
if (integerOnly != null) {
and.and(descriptorPath.integerOnly.eq(integerOnly));
......
......@@ -26,6 +26,7 @@ import org.genesys.blocks.model.filters.UuidModelFilter;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
import org.genesys2.server.model.PublishState;
/**
* The Class DescriptorListFilter.
......@@ -53,8 +54,8 @@ public class DescriptorListFilter extends UuidModelFilter {
/** The crop. */
public Set<String> crop;
/** The published. */
public Boolean published;
/** The publish state. */
public Set<PublishState> state;
/** The publisher. */
public Set<String> publisher;
......@@ -71,8 +72,8 @@ public class DescriptorListFilter extends UuidModelFilter {
if (crop != null && !crop.isEmpty()) {
and.and(descriptorList.crop.in(crop));
}
if (published != null) {
and.and(descriptorList.published.eq(published));
if (state != null && !state.isEmpty()) {
and.and(descriptorList.state.in(state));
}
if (publisher != null && !publisher.isEmpty()) {
and.and(descriptorList.publisher.in(publisher));
......
......@@ -23,6 +23,7 @@ import org.genesys.catalog.model.Partner;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.vocab.ControlledVocabulary;
import org.genesys.catalog.model.vocab.VocabularyTerm;
import org.genesys2.server.model.PublishState;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
......@@ -130,7 +131,8 @@ public class Descriptor extends UuidModel implements SelfCleaning, Publishable,
private String publisher;
/** Not published by default. */
private boolean published = false;
@Enumerated(EnumType.ORDINAL)
private PublishState state = PublishState.DRAFT;
/** Allow only integers, no decimal numbers. */
private Boolean integerOnly;
......@@ -235,7 +237,7 @@ public class Descriptor extends UuidModel implements SelfCleaning, Publishable,
* @param descriptor the descriptor
*/
public Descriptor(final Descriptor descriptor) {
this(descriptor.getVersionTag(), descriptor.getTitle(), descriptor.description, descriptor.getDataType(), descriptor.isPublished(), descriptor.isKey(), descriptor
this(descriptor.getVersionTag(), descriptor.getTitle(), descriptor.description, descriptor.getDataType(), descriptor.getState(), descriptor.isKey(), descriptor
.getIntegerOnly(), descriptor.getMinValue(), descriptor.getMaxValue(), descriptor.getColumnName(), descriptor.getUom(), descriptor.getVocabulary(), descriptor
.getOwner(), descriptor.getDescriptorLists());
}
......@@ -247,7 +249,7 @@ public class Descriptor extends UuidModel implements SelfCleaning, Publishable,
* @param title the title
* @param description the description
* @param dataType the data type
* @param published the published
* @param state the publish state
* @param key the key
* @param integerOnly the integer only
* @param minValue the min value
......@@ -258,14 +260,14 @@ public class Descriptor extends UuidModel implements SelfCleaning, Publishable,
* @param owner the owner
* @param descriptorLists the descriptor lists
*/
public Descriptor(final String versionTag, final String title, final String description, final DataType dataType, final boolean published, final boolean key,
public Descriptor(final String versionTag, final String title, final String description, final DataType dataType, final PublishState state, final boolean key,
final Boolean integerOnly, final Double minValue, final Double maxValue, final String columnName, final String uom, final ControlledVocabulary vocabulary,
final Partner owner, final List<DescriptorList> descriptorLists) {
this.versionTag = versionTag;
this.title = title;
this.description = description;
this.dataType = dataType;
this.published = published;
this.state = state;
this.key = key;
this.integerOnly = integerOnly;
this.minValue = minValue;
......@@ -566,16 +568,25 @@ public class Descriptor extends UuidModel implements SelfCleaning, Publishable,
*/
@Override
public boolean isPublished() {
return published;
return this.state == PublishState.PUBLISHED;
}
/**
* Sets the published.
* Gets the state.
*
* @param published the published to set
* @return the state
*/
public void setPublished(final boolean published) {
this.published = published;
public PublishState getState() {
return state;
}
/**
* Sets the publish state.
*
* @param state the new publish state
*/
public void setState(final PublishState state) {
this.state = state;
}
/**
......
......@@ -26,6 +26,7 @@ import org.genesys.blocks.model.SelfCleaning;
import org.genesys.blocks.model.UuidModel;
import org.genesys.blocks.security.model.AclAwareModel;
import org.genesys.catalog.model.Partner;
import org.genesys2.server.model.PublishState;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
......@@ -70,7 +71,8 @@ public class DescriptorList extends UuidModel implements Publishable, SelfCleani
private String description;
/** Not published by default. */
private boolean published = false;
@Enumerated(EnumType.ORDINAL)
private PublishState state = PublishState.DRAFT;
/** Trait URL. */
private String url;
......@@ -268,16 +270,25 @@ public class DescriptorList extends UuidModel implements Publishable, SelfCleani
*/
@Override
public boolean isPublished() {
return this.published;
return this.state == PublishState.PUBLISHED;
}
/**
* Sets the published.
* Gets the state.
*
* @param published the new published
* @return the state
*/
public void setPublished(final boolean published) {
this.published = published;
public PublishState getState() {
return state;
}
/**
* Sets the publish state.
*
* @param state the new publish state
*/
public void setState(final PublishState state) {
this.state = state;
}
/**
......
......@@ -73,6 +73,6 @@ public interface DatasetRepository extends JpaRepository<Dataset, Long>, QueryDs
*
* @return the data about last published datasets
*/
@Query("select year(d.lastModifiedDate), month(d.lastModifiedDate), day(d.lastModifiedDate), d.title, d.uuid, d.owner.shortName from Dataset d where d.published = true order by year(d.lastModifiedDate) desc, month(d.lastModifiedDate) desc, day(d.lastModifiedDate) desc")
@Query("select year(d.lastModifiedDate), month(d.lastModifiedDate), day(d.lastModifiedDate), d.title, d.uuid, d.owner.shortName from Dataset d where d.state = 1 order by year(d.lastModifiedDate) desc, month(d.lastModifiedDate) desc, day(d.lastModifiedDate) desc")
List<Object[]> lastPublished();
}
......@@ -200,13 +200,21 @@ public interface DatasetService {
Dataset upsertAccessions(Dataset dataset, Set<AccessionIdentifier> accessionIdentifiers) throws NotFoundElement;
/**
* Validates and publishes an unpublished dataset.
* 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 published dataset
* @return dataset in REVIEWING state
*/
Dataset publishDataset(Dataset dataset);
/**
* Validates and publishes an unpublished dataset. Admin - only.
*
* @param dataset the dataset
* @return published dataset
*/
Dataset approveDataset(Dataset dataset);
/**
* Un-publishes a dataset. Admin and the user with MANAGE permission - only.
*
......
......@@ -134,14 +134,22 @@ public interface DescriptorListService {
DescriptorList deleteDescriptorList(DescriptorList descriptorList);
/**
* Publish an unpublished descriptor list. The method validates the data and
* sets the {@link DescriptorList#isPublished()} flag to <code>true</code>.
* Puts the descriptorList into the Review state to be reviewed by admin.
* Admin and the user with MANAGE permission - only.
*
* @param descriptorList an unpublished descriptor list
* @return published descriptor list
* @param descriptorList the descriptor
* @return descriptor in REVIEWING state
*/
DescriptorList publishDescriptorList(DescriptorList descriptorList);
/**
* Validates and publishes an unpublished descriptorList. Admin - only.
*
* @param descriptorList the descriptorList
* @return published descriptorList
*/
DescriptorList approveDescriptorList(DescriptorList descriptorList);
/**
* Un-publish a published descriptor list. Admin and the user with MANAGE permission - only.
*
......
......@@ -111,14 +111,22 @@ public interface DescriptorService {
List<Descriptor> upsertDescriptors(List<Descriptor> source);
/**
* Publish an unpublished descriptor. The method validates the data and sets the
* {@link Descriptor#isPublished()} flag to <code>true</code>.
* Puts the descriptor into the Review state to be reviewed by admin.
* Admin and the user with MANAGE permission - only.
*
* @param descriptor an unpublished descriptor
* @return published descriptor
* @param descriptor the descriptor
* @return descriptor in REVIEWING state
*/
Descriptor publishDescriptor(Descriptor descriptor);
/**
* Validates and publishes an unpublished descriptor. Admin - only.
*
* @param descriptor the descriptor
* @return published descriptor
*/
Descriptor approveDescriptor(Descriptor descriptor);
/**
* Un-publish a published descriptor. Admin and the user with MANAGE permission - only.
*
......
......@@ -46,6 +46,7 @@ import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFileException;
import org.genesys.filerepository.model.RepositoryFile;
import org.genesys.filerepository.service.RepositoryService;
import org.genesys2.server.model.PublishState;
import org.genesys2.server.model.UserRole;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.security.SecurityUtils;
......@@ -155,6 +156,7 @@ public class DatasetServiceImpl implements DatasetService {
}
copyValues(dataset, input);
dataset.setState(PublishState.DRAFT);
return lazyLoad(datasetRepository.save(dataset));
}
......@@ -191,6 +193,8 @@ public class DatasetServiceImpl implements DatasetService {
} else {
dataset.getDescriptors().add(inputDescriptor);
descriptorUuids.add(inputDescriptor.getUuid());
// We will change its PublishState only if we add at least one new Descriptor
dataset.setState(PublishState.DRAFT);
}
}
......@@ -212,6 +216,7 @@ public class DatasetServiceImpl implements DatasetService {
// Keep descriptors that are not in the list
dataset.setDescriptors(dataset.getDescriptors().stream().filter(descriptor -> !descriptorUuids.contains(descriptor.getUuid())).collect(Collectors.toList()));
dataset.setState(PublishState.DRAFT);
return lazyLoad(datasetRepository.save(dataset));
}
......@@ -236,7 +241,7 @@ public class DatasetServiceImpl implements DatasetService {
* {@inheritDoc}
*/
@Override
@PostAuthorize("hasRole('ADMINISTRATOR') || returnObject==null || returnObject.published || hasPermission(returnObject, 'read')")
@PostAuthorize("hasRole('ADMINISTRATOR') || returnObject==null || returnObject.isPublished() || hasPermission(returnObject, 'read')")