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