Commit b4f0af2c authored by Matija Obreza's avatar Matija Obreza

Merge branch '286-publishing-things'

* 286-publishing-things:
  Keep compatibility with non updated frontend clients.
  Publishing things
parents d0f4c654 5f87f4c7
......@@ -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,32 +204,72 @@ 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);
}
//FIXME Remove it as soon as frontend clients start supporting PublishState
/**
* 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);
if (published) {
return datasetService.publishDataset(dataset);
return datasetService.approveDataset(dataset);
} else {
return datasetService.unpublishDataset(dataset);
return datasetService.rejectDataset(dataset);
}
}
/**
* 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);
}
/**
* 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.
*
......
......@@ -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,24 +244,63 @@ 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);
if (published) {
return descriptorService.publishDescriptor(descriptor);
return descriptorService.approveDescriptor(descriptor);
} else {
return descriptorService.unpublishDescriptor(descriptor);
return descriptorService.rejectDescriptor(descriptor);
}
}
/**
* 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 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);
}
}
......@@ -117,26 +117,65 @@ 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);
if (published) {
return descriptorListService.publishDescriptorList(descriptorList);
return descriptorListService.approveDescriptorList(descriptorList);
} else {
return descriptorListService.unpublishDescriptorList(descriptorList);
return descriptorListService.rejectDescriptorList(descriptorList);
}
}
/**
* 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);
}
/**
* 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.
*
......@@ -241,9 +280,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,6 +57,10 @@ public class DatasetFilter extends UuidModelFilter {
/** The language. */
public Set<String> language;
/** The publish state. */
public Set<PublishState> state;
//FIXME Remove it as soon as frontend clients start supporting PublishState
/** The published. */
public Boolean published;
......@@ -71,8 +76,12 @@ public class DatasetFilter extends UuidModelFilter {
final BooleanBuilder and = new BooleanBuilder();
super.buildQuery(dataset._super, and);
if (state != null && !state.isEmpty()) {
and.and(dataset.state.in(state));
}
if (published != null) {
and.and(dataset.published.eq(published));
final PublishState publishState = published ? PublishState.PUBLISHED : PublishState.DRAFT;
and.and(dataset.state.in(publishState));
}
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,6 +75,10 @@ public class DescriptorFilter extends UuidModelFilter {
/** The publisher. */
public Set<String> publisher;
/** The publish state. */
public Set<PublishState> state;
//FIXME Remove it as soon as frontend clients start supporting PublishState
/** The published. */
public Boolean published;
......@@ -114,8 +119,12 @@ public class DescriptorFilter extends UuidModelFilter {
if (publisher != null && !publisher.isEmpty()) {
and.and(descriptorPath.publisher.in(publisher));
}
if (state != null && !state.isEmpty()) {
and.and(descriptorPath.state.in(state));
}
if (published != null) {
and.and(descriptorPath.published.eq(published));
final PublishState publishState = published ? PublishState.PUBLISHED : PublishState.DRAFT;
and.and(descriptorPath.state.in(publishState));
}
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,6 +54,10 @@ public class DescriptorListFilter extends UuidModelFilter {
/** The crop. */
public Set<String> crop;
/** The publish state. */
public Set<PublishState> state;
//FIXME Remove it as soon as frontend clients start supporting PublishState
/** The published. */
public Boolean published;
......@@ -71,8 +76,12 @@ public class DescriptorListFilter extends UuidModelFilter {
if (crop != null && !crop.isEmpty()) {
and.and(descriptorList.crop.in(crop));
}
if (state != null && !state.isEmpty()) {
and.and(descriptorList.state.in(state));
}
if (published != null) {
and.and(descriptorList.published.eq(published));
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));
......
......@@ -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;
}
/**