Commit 130bfea1 authored by Maxym Borodenko's avatar Maxym Borodenko
Browse files

Remove unnecessary endpoints; reconsider services; cleanup corresponding filters and tests

parent e9f1b92d
...@@ -209,28 +209,6 @@ public class DatasetController { ...@@ -209,28 +209,6 @@ public class DatasetController {
return datasetService.upsertAccessions(dataset, accessionIdentifiers); 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
*
* @param uuid dataset UUID
* @param version record version
* @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) {
final Dataset dataset = datasetService.loadDataset(uuid, version);
if (published) {
return datasetService.approveDataset(dataset);
} else {
return datasetService.rejectDataset(dataset);
}
}
/** /**
* Loads dataset by uuid and version and tries to publish it. * Loads dataset by uuid and version and tries to publish it.
* *
......
...@@ -254,27 +254,6 @@ public class DescriptorController { ...@@ -254,27 +254,6 @@ public class DescriptorController {
return descriptorService.removeDescriptor(descriptorService.getDescriptor(uuid, version)); return descriptorService.removeDescriptor(descriptorService.getDescriptor(uuid, version));
} }
/**
* Loads descriptor by uuid and version and sets new publish state
*
* @param uuid descriptor UUID
* @param version record version
* @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) {
final Descriptor descriptor = descriptorService.getDescriptor(uuid, version);
if (published) {
return descriptorService.approveDescriptor(descriptor);
} else {
return descriptorService.rejectDescriptor(descriptor);
}
}
/** /**
* Loads descriptor by uuid and version and tries to publish it. * Loads descriptor by uuid and version and tries to publish it.
* *
......
...@@ -116,27 +116,6 @@ public class DescriptorListController { ...@@ -116,27 +116,6 @@ public class DescriptorListController {
response.flushBuffer(); response.flushBuffer();
} }
/**
* Loads descriptorList by uuid and version and sets new publish state
*
* @param uuid descriptorList UUID
* @param version record version
* @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) {
final DescriptorList descriptorList = descriptorListService.getDescriptorList(uuid, version);
if (published) {
return descriptorListService.approveDescriptorList(descriptorList);
} else {
return descriptorListService.rejectDescriptorList(descriptorList);
}
}
/** /**
* Loads DescriptorList by uuid and version and tries to publish it. * Loads DescriptorList by uuid and version and tries to publish it.
* *
......
...@@ -60,10 +60,6 @@ public class DatasetFilter extends UuidModelFilter { ...@@ -60,10 +60,6 @@ public class DatasetFilter extends UuidModelFilter {
/** The publish state. */ /** The publish state. */
public Set<PublishState> state; public Set<PublishState> state;
//FIXME Remove it as soon as frontend clients start supporting PublishState
/** The published. */
public Boolean published;
/** The crop. */ /** The crop. */
public Set<String> crop; public Set<String> crop;
...@@ -79,10 +75,6 @@ public class DatasetFilter extends UuidModelFilter { ...@@ -79,10 +75,6 @@ public class DatasetFilter extends UuidModelFilter {
if (state != null && !state.isEmpty()) { if (state != null && !state.isEmpty()) {
and.and(dataset.state.in(state)); 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) { if (title != null) {
and.and(title.buildQuery(dataset.title)); and.and(title.buildQuery(dataset.title));
} }
......
...@@ -78,10 +78,6 @@ public class DescriptorFilter extends UuidModelFilter { ...@@ -78,10 +78,6 @@ public class DescriptorFilter extends UuidModelFilter {
/** The publish state. */ /** The publish state. */
public Set<PublishState> state; public Set<PublishState> state;
//FIXME Remove it as soon as frontend clients start supporting PublishState
/** The published. */
public Boolean published;
/** The integer only. */ /** The integer only. */
public Boolean integerOnly; public Boolean integerOnly;
...@@ -122,10 +118,6 @@ public class DescriptorFilter extends UuidModelFilter { ...@@ -122,10 +118,6 @@ public class DescriptorFilter extends UuidModelFilter {
if (state != null && !state.isEmpty()) { if (state != null && !state.isEmpty()) {
and.and(descriptorPath.state.in(state)); 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) { if (integerOnly != null) {
and.and(descriptorPath.integerOnly.eq(integerOnly)); and.and(descriptorPath.integerOnly.eq(integerOnly));
} }
......
...@@ -57,10 +57,6 @@ public class DescriptorListFilter extends UuidModelFilter { ...@@ -57,10 +57,6 @@ public class DescriptorListFilter extends UuidModelFilter {
/** The publish state. */ /** The publish state. */
public Set<PublishState> state; public Set<PublishState> state;
//FIXME Remove it as soon as frontend clients start supporting PublishState
/** The published. */
public Boolean published;
/** The publisher. */ /** The publisher. */
public Set<String> publisher; public Set<String> publisher;
...@@ -79,10 +75,6 @@ public class DescriptorListFilter extends UuidModelFilter { ...@@ -79,10 +75,6 @@ public class DescriptorListFilter extends UuidModelFilter {
if (state != null && !state.isEmpty()) { if (state != null && !state.isEmpty()) {
and.and(descriptorList.state.in(state)); 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()) { if (publisher != null && !publisher.isEmpty()) {
and.and(descriptorList.publisher.in(publisher)); and.and(descriptorList.publisher.in(publisher));
} }
......
...@@ -450,8 +450,7 @@ public class DatasetServiceImpl implements DatasetService { ...@@ -450,8 +450,7 @@ public class DatasetServiceImpl implements DatasetService {
*/ */
@Override @Override
@Transactional @Transactional
// FIXME Should be only for admins. Fix after frontend clients start supporting PublishState @PreAuthorize("hasRole('ADMINISTRATOR')")
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#dataset, 'write')")
public Dataset approveDataset(final Dataset dataset) { public Dataset approveDataset(final Dataset dataset) {
final Dataset loaded = datasetRepository.findByUuidAndVersion(dataset.getUuid(), dataset.getVersion()); final Dataset loaded = datasetRepository.findByUuidAndVersion(dataset.getUuid(), dataset.getVersion());
if (loaded == null) { if (loaded == null) {
...@@ -460,11 +459,9 @@ public class DatasetServiceImpl implements DatasetService { ...@@ -460,11 +459,9 @@ public class DatasetServiceImpl implements DatasetService {
if (loaded.isPublished()) { if (loaded.isPublished()) {
throw new InvalidApiUsageException("Dataset is already published"); throw new InvalidApiUsageException("Dataset is already published");
} }
if (loaded.getState() == PublishState.DRAFT) {
// FIXME Uncomment it as soon as frontend clients start supporting PublishState throw new InvalidApiUsageException("Dataset should be sent for review before publication");
// if (loaded.getState() == PublishState.DRAFT) { }
// throw new InvalidApiUsageException("Dataset should be sent for review before publication");
// }
loaded.setState(PublishState.PUBLISHED); loaded.setState(PublishState.PUBLISHED);
......
...@@ -333,8 +333,7 @@ public class DescriptorListServiceImpl implements DescriptorListService { ...@@ -333,8 +333,7 @@ public class DescriptorListServiceImpl implements DescriptorListService {
*/ */
@Override @Override
@Transactional @Transactional
// FIXME Should be only for admins. Fix after frontend clients start supporting PublishState @PreAuthorize("hasRole('ADMINISTRATOR')")
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#descriptorList, 'WRITE')")
public DescriptorList approveDescriptorList(final DescriptorList descriptorList) { public DescriptorList approveDescriptorList(final DescriptorList descriptorList) {
final DescriptorList loaded = descriptorListRepository.findByUuidAndVersion(descriptorList.getUuid(), descriptorList.getVersion()); final DescriptorList loaded = descriptorListRepository.findByUuidAndVersion(descriptorList.getUuid(), descriptorList.getVersion());
if (loaded == null) { if (loaded == null) {
...@@ -343,10 +342,9 @@ public class DescriptorListServiceImpl implements DescriptorListService { ...@@ -343,10 +342,9 @@ public class DescriptorListServiceImpl implements DescriptorListService {
if (loaded.isPublished()) { if (loaded.isPublished()) {
throw new InvalidApiUsageException("Descriptor List is already published"); throw new InvalidApiUsageException("Descriptor List is already published");
} }
// FIXME Uncomment it as soon as frontend clients start supporting PublishState if (loaded.getState() == PublishState.DRAFT) {
// if (loaded.getState() == PublishState.DRAFT) { throw new InvalidApiUsageException("Descriptor List should be sent for review before publication");
// throw new InvalidApiUsageException("Descriptor List should be sent for review before publication"); }
// }
for (final Descriptor descriptor : loaded.getDescriptors()) { for (final Descriptor descriptor : loaded.getDescriptors()) {
if (descriptor.getState() == PublishState.REVIEWING) { if (descriptor.getState() == PublishState.REVIEWING) {
......
...@@ -329,8 +329,7 @@ public class DescriptorServiceImpl implements DescriptorService { ...@@ -329,8 +329,7 @@ public class DescriptorServiceImpl implements DescriptorService {
*/ */
@Override @Override
@Transactional @Transactional
// FIXME Should be only for admins. Fix after frontend clients start supporting PublishState @PreAuthorize("hasRole('ADMINISTRATOR')")
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#descriptor, 'WRITE')")
public Descriptor approveDescriptor(final Descriptor descriptor) { public Descriptor approveDescriptor(final Descriptor descriptor) {
final Descriptor loaded = descriptorRepository.findByUuidAndVersion(descriptor.getUuid(), descriptor.getVersion()); final Descriptor loaded = descriptorRepository.findByUuidAndVersion(descriptor.getUuid(), descriptor.getVersion());
if (loaded == null) { if (loaded == null) {
...@@ -339,10 +338,9 @@ public class DescriptorServiceImpl implements DescriptorService { ...@@ -339,10 +338,9 @@ public class DescriptorServiceImpl implements DescriptorService {
if (loaded.isPublished()) { if (loaded.isPublished()) {
throw new InvalidApiUsageException("Descriptor is already published"); throw new InvalidApiUsageException("Descriptor is already published");
} }
// FIXME Uncomment it as soon as frontend clients start supporting PublishState if (loaded.getState() == PublishState.DRAFT) {
// if (loaded.getState() == PublishState.DRAFT) { throw new InvalidApiUsageException("Descriptor should be sent for review before publication");
// throw new InvalidApiUsageException("Descriptor should be sent for review before publication"); }
// }
loaded.setState(PublishState.PUBLISHED); loaded.setState(PublishState.PUBLISHED);
return lazyLoad(descriptorRepository.save(loaded)); return lazyLoad(descriptorRepository.save(loaded));
......
...@@ -65,30 +65,6 @@ public class DatasetControllerTest extends AbstractApiTest { ...@@ -65,30 +65,6 @@ public class DatasetControllerTest extends AbstractApiTest {
/*@formatter:on*/ /*@formatter:on*/
} }
//FIXME Remove test as soon as frontend clients start supporting PublishState
@Test
@WithMockUser(username = "user", password = "user", roles = "ADMINISTRATOR")
public void publishDataset() throws Exception {
Dataset dataset = setUpDataset(PublishState.DRAFT);
dataset = datasetService.createDataset(dataset);
assertThat(dataset.getState(), is(PublishState.DRAFT));
/*@formatter:off*/
mockMvc
.perform(post(DatasetController.CONTROLLER_URL.concat("/publish"))
.param("uuid", dataset.getUuid().toString())
.param("version", dataset.getVersion().toString()))
// .andDo(MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$", not(nullValue())))
.andExpect(jsonPath("$.uuid", is(dataset.getUuid().toString())))
.andExpect(jsonPath("$.state", is(PublishState.PUBLISHED.name())))
// .andExpect(jsonPath("$.version", is(dataset.getVersion() + 1)))
.andDo(document("dataset-publish"));
/*@formatter:on*/
}
@Test @Test
@WithMockUser(username = "user", password = "user", roles = "ADMINISTRATOR") @WithMockUser(username = "user", password = "user", roles = "ADMINISTRATOR")
public void approveDataset() throws Exception { public void approveDataset() throws Exception {
...@@ -153,34 +129,6 @@ public class DatasetControllerTest extends AbstractApiTest { ...@@ -153,34 +129,6 @@ public class DatasetControllerTest extends AbstractApiTest {
/*@formatter:on*/ /*@formatter:on*/
} }
//FIXME Remove it as soon as frontend clients start supporting PublishState
@Test
@WithMockUser(username = "user", password = "user", roles = "ADMINISTRATOR")
public void unpublishDataset() throws Exception {
Dataset dataset = setUpDataset(PublishState.DRAFT);
dataset = datasetService.createDataset(dataset);
/*@formatter:off*/
mockMvc
.perform(post(DatasetController.CONTROLLER_URL.concat("/publish"))
.param("uuid", dataset.getUuid().toString())
.param("version", dataset.getVersion().toString()))
// .andDo(MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.state", is(PublishState.PUBLISHED.name())))
;
mockMvc
.perform(post(DatasetController.CONTROLLER_URL.concat("/publish"))
.param("uuid", dataset.getUuid().toString())
.param("version", "" + (dataset.getVersion() + 1))
.param("published", "false"))
// .andDo(MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.state", is(PublishState.DRAFT.name())));
/*@formatter:on*/
}
@Test @Test
@WithMockUser(username = "user", password = "user", roles = "USER") @WithMockUser(username = "user", password = "user", roles = "USER")
@Ignore @Ignore
......
...@@ -272,28 +272,6 @@ public class DescriptorControllerTest extends AbstractApiTest { ...@@ -272,28 +272,6 @@ public class DescriptorControllerTest extends AbstractApiTest {
/*@formatter:on*/ /*@formatter:on*/
} }
//FIXME Remove test as soon as frontend clients start supporting PublishState
@Test
@WithMockOAuth2Authentication(roles = { "ADMINISTRATOR" }, scopes = { "write" })
public void publishDescriptorTest() throws Exception {
Descriptor descriptor = setUpDescriptor(PublishState.DRAFT);
descriptor = descriptorRepository.save(descriptor);
/*@formatter:off*/
mockMvc
.perform(post(DescriptorController.CONTROLLER_URL.concat("/publish"))
.param("uuid", descriptor.getUuid().toString())
.param("version", descriptor.getVersion().toString()))
// .andDo(MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$", not(nullValue())))
.andExpect(jsonPath("$.uuid", is(descriptor.getUuid().toString())))
.andExpect(jsonPath("$.state", is(PublishState.PUBLISHED.name())))
.andDo(document("descriptor-publish"));
/*@formatter:on*/
}
@Test @Test
@WithMockOAuth2Authentication(roles = { "ADMINISTRATOR" }, scopes = { "write" }) @WithMockOAuth2Authentication(roles = { "ADMINISTRATOR" }, scopes = { "write" })
public void approveDescriptorTest() throws Exception { public void approveDescriptorTest() throws Exception {
......
...@@ -305,27 +305,6 @@ public class DescriptorListControllerTest extends AbstractApiTest { ...@@ -305,27 +305,6 @@ public class DescriptorListControllerTest extends AbstractApiTest {
/*@formatter:on*/ /*@formatter:on*/
} }
//FIXME Remove test as soon as frontend clients start supporting PublishState
@Test
@WithMockUser(username = "user", password = "user", roles = "ADMINISTRATOR")
public void publishDescriptorListTest() throws Exception {
DescriptorList descriptorList = setUpDescriptorList(PublishState.DRAFT, UUID.randomUUID(), "Des 2", "Title 2", "Vt 2");
descriptorList = descriptorListRepository.save(descriptorList);
/*@formatter:off*/
mockMvc
.perform(post(DescriptorListController.CONTROLLER_URL.concat("/publish"))
.param("uuid", descriptorList.getUuid().toString())
.param("version", descriptorList.getVersion().toString()))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$", not(nullValue())))
.andExpect(jsonPath("$.uuid", is(descriptorList.getUuid().toString())))
.andExpect(jsonPath("$.state", is(PublishState.PUBLISHED.name())))
.andDo(document("descriptorList-publish"));
/*@formatter:on*/
}
@Test @Test
@WithMockUser(username = "user", password = "user", roles = "ADMINISTRATOR") @WithMockUser(username = "user", password = "user", roles = "ADMINISTRATOR")
public void reviewDescriptorListTest() throws Exception { public void reviewDescriptorListTest() throws Exception {
......
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