Commit 709599d7 authored by Matija Obreza's avatar Matija Obreza
Browse files

Fix: Cannot create Subset with outdated owner

parent b5908b0c
...@@ -32,7 +32,6 @@ import javax.validation.ConstraintViolation; ...@@ -32,7 +32,6 @@ import javax.validation.ConstraintViolation;
import javax.validation.Validator; import javax.validation.Validator;
import org.genesys.blocks.model.JsonViews; import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.service.PartnerService;
import org.genesys.catalog.service.ShortFilterService.FilterInfo; import org.genesys.catalog.service.ShortFilterService.FilterInfo;
import org.genesys.taxonomy.gringlobal.component.CabReader; import org.genesys.taxonomy.gringlobal.component.CabReader;
import org.genesys2.server.api.ApiBaseController; import org.genesys2.server.api.ApiBaseController;
...@@ -110,9 +109,6 @@ public class SubsetController extends ApiBaseController { ...@@ -110,9 +109,6 @@ public class SubsetController extends ApiBaseController {
@Autowired @Autowired
private SubsetService subsetService; private SubsetService subsetService;
@Autowired
private PartnerService partnerService;
/** The short filter service. */ /** The short filter service. */
@Autowired @Autowired
protected ShortFilterProcessor shortFilterProcessor; protected ShortFilterProcessor shortFilterProcessor;
...@@ -132,12 +128,7 @@ public class SubsetController extends ApiBaseController { ...@@ -132,12 +128,7 @@ public class SubsetController extends ApiBaseController {
*/ */
@PostMapping(value = "/create", produces = { MediaType.APPLICATION_JSON_VALUE }) @PostMapping(value = "/create", produces = { MediaType.APPLICATION_JSON_VALUE })
public Subset create(@RequestBody final Subset subset) { public Subset create(@RequestBody final Subset subset) {
// FaoInstitute institute = instituteService.findInstitute(subset.getWiewsCode()); return subsetService.create(subset);
var partner = partnerService.reload(subset.getOwner());
if (partner == null) {
throw new NotFoundElement("No such partner.");
}
return subsetService.create(partner, subset);
} }
/** /**
......
...@@ -25,9 +25,6 @@ import java.util.UUID; ...@@ -25,9 +25,6 @@ import java.util.UUID;
import javax.validation.Valid; import javax.validation.Valid;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import org.genesys.catalog.model.Partner;
import org.genesys2.server.api.FilteredPage; import org.genesys2.server.api.FilteredPage;
import org.genesys2.server.exception.NotFoundElement; import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.genesys.Accession; import org.genesys2.server.model.genesys.Accession;
...@@ -35,12 +32,14 @@ import org.genesys2.server.model.impl.FaoInstitute; ...@@ -35,12 +32,14 @@ import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Subset; import org.genesys2.server.model.impl.Subset;
import org.genesys2.server.model.impl.SubsetAccessionRef; import org.genesys2.server.model.impl.SubsetAccessionRef;
import org.genesys2.server.model.impl.SubsetCreator; import org.genesys2.server.model.impl.SubsetCreator;
import org.genesys2.server.service.ElasticsearchService.TermResult;
import org.genesys2.server.service.filter.SubsetFilter; import org.genesys2.server.service.filter.SubsetFilter;
import org.genesys2.server.service.impl.SearchException; import org.genesys2.server.service.impl.SearchException;
import org.genesys2.server.service.ElasticsearchService.TermResult;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
/** /**
* @author Maxym Borodenko * @author Maxym Borodenko
*/ */
...@@ -84,11 +83,10 @@ public interface SubsetService { ...@@ -84,11 +83,10 @@ public interface SubsetService {
/** /**
* Method creating Subset. * Method creating Subset.
* *
* @param partner the institute owning the subset
* @param source the source * @param source the source
* @return saved Subset in db. * @return saved Subset in db.
*/ */
Subset create(Partner partner, @Valid Subset source); Subset create(@Valid Subset source);
/** /**
* Load subset based on identifiers and version provided in the input. * Load subset based on identifiers and version provided in the input.
......
...@@ -200,8 +200,8 @@ public class SubsetServiceImpl implements SubsetService { ...@@ -200,8 +200,8 @@ public class SubsetServiceImpl implements SubsetService {
*/ */
@Override @Override
@Transactional @Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#partner, 'CREATE')") @PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#source.owner, 'CREATE')")
public Subset create(final Partner partner, final Subset source) { public Subset create(final Subset source) {
LOG.info("Create Subset."); LOG.info("Create Subset.");
final SubsetVersions subsetVersions = new SubsetVersions(); final SubsetVersions subsetVersions = new SubsetVersions();
......
...@@ -415,7 +415,7 @@ public class SubsetServiceTest extends CatalogServiceTest { ...@@ -415,7 +415,7 @@ public class SubsetServiceTest extends CatalogServiceTest {
subset.setOwner(partner); subset.setOwner(partner);
subset.setUuid(uuid); subset.setUuid(uuid);
return subsetService.create(partner, subset); return subsetService.create(subset);
} }
private Subset createSubset(String title) { private Subset createSubset(String title) {
...@@ -423,7 +423,7 @@ public class SubsetServiceTest extends CatalogServiceTest { ...@@ -423,7 +423,7 @@ public class SubsetServiceTest extends CatalogServiceTest {
subset.setTitle(title); subset.setTitle(title);
subset.setOwner(partner); subset.setOwner(partner);
return subsetService.create(partner, subset); return subsetService.create(subset);
} }
private Partner createPartner() { private Partner createPartner() {
......
...@@ -147,7 +147,7 @@ public abstract class AbstractSubsetControllerTest extends AbstractApiTest { ...@@ -147,7 +147,7 @@ public abstract class AbstractSubsetControllerTest extends AbstractApiTest {
protected Subset toPublished(Subset subset) { protected Subset toPublished(Subset subset) {
if (subsetRepository.getByUuid(subset.getUuid()) == null) { if (subsetRepository.getByUuid(subset.getUuid()) == null) {
subset = subsetService.create(owner, subset); subset = subsetService.create(subset);
assertEquals(subset.getState(), PublishState.DRAFT); assertEquals(subset.getState(), PublishState.DRAFT);
} }
if (subset.getState() == PublishState.DRAFT) { if (subset.getState() == PublishState.DRAFT) {
......
...@@ -121,7 +121,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest { ...@@ -121,7 +121,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest {
@Test @Test
public void updateSubsetTest() throws Exception { public void updateSubsetTest() throws Exception {
final Subset storedSubset = subsetService.create(owner, setUpSubset()); final Subset storedSubset = subsetService.create(setUpSubset());
storedSubset.setTitle(TITLE_2); storedSubset.setTitle(TITLE_2);
storedSubset.setDescription(DESCRIPTION_2); storedSubset.setDescription(DESCRIPTION_2);
storedSubset.getInstitute().setSettings(null); storedSubset.getInstitute().setSettings(null);
...@@ -146,7 +146,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest { ...@@ -146,7 +146,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest {
@Test @Test
public void getSubsetTest() throws Exception { public void getSubsetTest() throws Exception {
final Subset subset = subsetService.create(owner, setUpSubset()); final Subset subset = subsetService.create(setUpSubset());
/*@formatter:off*/ /*@formatter:off*/
mockMvc.perform(get(SubsetController.CONTROLLER_URL.concat("/{uuid}"), subset.getUuid()) mockMvc.perform(get(SubsetController.CONTROLLER_URL.concat("/{uuid}"), subset.getUuid())
...@@ -160,7 +160,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest { ...@@ -160,7 +160,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest {
@Test @Test
public void deleteSubsetTest() throws Exception { public void deleteSubsetTest() throws Exception {
final Subset subset = subsetService.create(owner, setUpSubset()); final Subset subset = subsetService.create(setUpSubset());
/*@formatter:off*/ /*@formatter:off*/
mockMvc.perform(delete(SubsetController.CONTROLLER_URL.concat("/{uuid},{version}"), subset.getUuid(), subset.getVersion()) mockMvc.perform(delete(SubsetController.CONTROLLER_URL.concat("/{uuid},{version}"), subset.getUuid(), subset.getVersion())
...@@ -216,7 +216,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest { ...@@ -216,7 +216,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest {
subset.setDateCreated(DATE_CREATED); subset.setDateCreated(DATE_CREATED);
subset.setSubsetType(Subset.SubsetType.REPRESENTATIVE); subset.setSubsetType(Subset.SubsetType.REPRESENTATIVE);
subset.setSelectionMethod("Banana taxonomy"); subset.setSelectionMethod("Banana taxonomy");
final Subset savedSubset = subsetService.create(owner, subset); final Subset savedSubset = subsetService.create(subset);
toPublished(savedSubset); toPublished(savedSubset);
SubsetFilter subsetFilter = new SubsetFilter(); SubsetFilter subsetFilter = new SubsetFilter();
...@@ -237,7 +237,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest { ...@@ -237,7 +237,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest {
@Test @Test
public void addAccessionsToSubsetTest() throws Exception { public void addAccessionsToSubsetTest() throws Exception {
final Subset subset = subsetService.create(owner, setUpSubset()); final Subset subset = subsetService.create(setUpSubset());
assertThat(subset, notNullValue()); assertThat(subset, notNullValue());
assertThat(subset.getAccessionCount(), is(0)); assertThat(subset.getAccessionCount(), is(0));
...@@ -259,7 +259,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest { ...@@ -259,7 +259,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest {
@Test @Test
public void loadMoreAccessionsTest() throws Exception { public void loadMoreAccessionsTest() throws Exception {
Subset subset = subsetService.create(owner, setUpSubset()); Subset subset = subsetService.create(setUpSubset());
assertThat(subset, notNullValue()); assertThat(subset, notNullValue());
assertThat(subset.getAccessionCount(), is(0)); assertThat(subset.getAccessionCount(), is(0));
...@@ -307,7 +307,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest { ...@@ -307,7 +307,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest {
@Test @Test
public void loadMoreSubsetAccessionsWithFullJsonTest() throws Exception { public void loadMoreSubsetAccessionsWithFullJsonTest() throws Exception {
Subset subset = subsetService.create(owner, setUpSubset()); Subset subset = subsetService.create(setUpSubset());
assertThat(subset, notNullValue()); assertThat(subset, notNullValue());
assertThat(subset.getAccessionCount(), is(0)); assertThat(subset.getAccessionCount(), is(0));
...@@ -346,7 +346,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest { ...@@ -346,7 +346,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest {
public void uploadAccessionsInFileTest() throws Exception { public void uploadAccessionsInFileTest() throws Exception {
assertThat(accessionRefRepository.count(), is(0L)); assertThat(accessionRefRepository.count(), is(0L));
Subset subset = subsetService.create(owner, setUpSubset()); Subset subset = subsetService.create(setUpSubset());
assertThat(subset, notNullValue()); assertThat(subset, notNullValue());
assertThat(subset.getState(), is(PublishState.DRAFT)); assertThat(subset.getState(), is(PublishState.DRAFT));
...@@ -377,7 +377,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest { ...@@ -377,7 +377,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest {
public void setOnlyValidAccessionsFromUploadedFileTest() throws Exception { public void setOnlyValidAccessionsFromUploadedFileTest() throws Exception {
assertThat(accessionRefRepository.count(), is(0L)); assertThat(accessionRefRepository.count(), is(0L));
Subset subset = subsetService.create(owner, setUpSubset()); Subset subset = subsetService.create(setUpSubset());
assertThat(subset, notNullValue()); assertThat(subset, notNullValue());
assertThat(subset.getState(), is(PublishState.DRAFT)); assertThat(subset.getState(), is(PublishState.DRAFT));
...@@ -410,7 +410,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest { ...@@ -410,7 +410,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest {
public void uploadNotCsvFileTest() throws Exception { public void uploadNotCsvFileTest() throws Exception {
assertThat(accessionRefRepository.count(), is(0L)); assertThat(accessionRefRepository.count(), is(0L));
Subset subset = subsetService.create(owner, setUpSubset()); Subset subset = subsetService.create(setUpSubset());
assertThat(subset, notNullValue()); assertThat(subset, notNullValue());
assertThat(subset.getState(), is(PublishState.DRAFT)); assertThat(subset.getState(), is(PublishState.DRAFT));
...@@ -432,7 +432,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest { ...@@ -432,7 +432,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest {
@Test @Test
@WithMockOAuth2Authentication(roles = { "ADMINISTRATOR" }, scopes = { "write" }) @WithMockOAuth2Authentication(roles = { "ADMINISTRATOR" }, scopes = { "write" })
public void approveSubsetTest() throws Exception { public void approveSubsetTest() throws Exception {
Subset subset = subsetService.create(owner, setUpSubset()); Subset subset = subsetService.create(setUpSubset());
assertEquals(subset.getState(), PublishState.DRAFT); assertEquals(subset.getState(), PublishState.DRAFT);
subset = subsetService.reviewSubset(subset); subset = subsetService.reviewSubset(subset);
assertEquals(subset.getState(), PublishState.REVIEWING); assertEquals(subset.getState(), PublishState.REVIEWING);
...@@ -457,7 +457,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest { ...@@ -457,7 +457,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest {
@Test @Test
@WithMockUser(username = "user", password = "user", roles = "ADMINISTRATOR") @WithMockUser(username = "user", password = "user", roles = "ADMINISTRATOR")
public void reviewSubsetTest() throws Exception { public void reviewSubsetTest() throws Exception {
final Subset subset = subsetService.create(owner, setUpSubset()); final Subset subset = subsetService.create(setUpSubset());
assertEquals(subset.getState(), PublishState.DRAFT); assertEquals(subset.getState(), PublishState.DRAFT);
/*@formatter:off*/ /*@formatter:off*/
...@@ -476,7 +476,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest { ...@@ -476,7 +476,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest {
@Test @Test
@WithMockUser(username = "user", password = "user", roles = "ADMINISTRATOR") @WithMockUser(username = "user", password = "user", roles = "ADMINISTRATOR")
public void rejectSubsetTest() throws Exception { public void rejectSubsetTest() throws Exception {
final Subset subset = subsetService.create(owner, setUpSubset()); final Subset subset = subsetService.create(setUpSubset());
assertEquals(subset.getState(), PublishState.DRAFT); assertEquals(subset.getState(), PublishState.DRAFT);
/*@formatter:off*/ /*@formatter:off*/
...@@ -495,7 +495,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest { ...@@ -495,7 +495,7 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest {
@Test @Test
public void createNewVersionTest() throws Exception { public void createNewVersionTest() throws Exception {
Subset subset = subsetService.create(owner, setUpSubset()); Subset subset = subsetService.create(setUpSubset());
assertEquals(subset.getState(), PublishState.DRAFT); assertEquals(subset.getState(), PublishState.DRAFT);
// add accessions // add accessions
......
Supports Markdown
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