Commit 71af5958 authored by Matija Obreza's avatar Matija Obreza

Updated Subset API

- delete method name is reserved in JS, use remove
- list subsets returns FilteredPage
- Updated JUnit configuration
parent 955dbf76
...@@ -137,7 +137,7 @@ public class ApiExceptionHandler { ...@@ -137,7 +137,7 @@ public class ApiExceptionHandler {
* @return the api error * @return the api error
*/ */
@ResponseStatus(code = HttpStatus.NOT_FOUND) @ResponseStatus(code = HttpStatus.NOT_FOUND)
@ExceptionHandler(NotFoundElement.class) @ExceptionHandler(value = { NotFoundElement.class, org.genesys2.server.exception.NotFoundElement.class })
@ResponseBody @ResponseBody
public ApiError<Exception> handleNotFound(final Exception e, final HttpServletRequest request) { public ApiError<Exception> handleNotFound(final Exception e, final HttpServletRequest request) {
LOG.warn("Element not found {} {}", request.getMethod(), request.getRequestURL(), e); LOG.warn("Element not found {} {}", request.getMethod(), request.getRequestURL(), e);
......
...@@ -21,6 +21,7 @@ package org.genesys.catalog.exceptions; ...@@ -21,6 +21,7 @@ package org.genesys.catalog.exceptions;
* *
* @author Andrey Lugovskoy. * @author Andrey Lugovskoy.
*/ */
// TODO Replace with org.genesys2.server.api.NotFoundElement
public class NotFoundElement extends InvalidApiUsageException { public class NotFoundElement extends InvalidApiUsageException {
private static final long serialVersionUID = 6621976491018091330L; private static final long serialVersionUID = 6621976491018091330L;
......
...@@ -16,14 +16,16 @@ ...@@ -16,14 +16,16 @@
package org.genesys2.server.api.v1; package org.genesys2.server.api.v1;
import java.io.IOException;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import org.genesys.catalog.api.FilteredPage;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys2.server.model.impl.Subset; import org.genesys2.server.model.impl.Subset;
import org.genesys2.server.service.SubsetService; import org.genesys2.server.service.SubsetService;
import org.genesys2.server.service.filter.SubsetFilter; import org.genesys2.server.service.filter.SubsetFilter;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
...@@ -40,15 +42,15 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -40,15 +42,15 @@ import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
/** /**
* The Class SubsetRestController. * The Class SubsetController.
* *
* @author Maxym Borodenko * @author Maxym Borodenko
*/ */
@RestController("subsetApi1") @RestController("subsetApi1")
@PreAuthorize("isAuthenticated()") @PreAuthorize("isAuthenticated()")
@RequestMapping(SubsetRestController.API_BASE) @RequestMapping(SubsetController.API_BASE)
@Api(tags = { "subset" }) @Api(tags = { "subset" })
public class SubsetRestController { public class SubsetController {
/** The Constant API_BASE. */ /** The Constant API_BASE. */
public static final String API_BASE = "/api/v1/subset"; public static final String API_BASE = "/api/v1/subset";
...@@ -56,6 +58,10 @@ public class SubsetRestController { ...@@ -56,6 +58,10 @@ public class SubsetRestController {
@Autowired @Autowired
private SubsetService subsetService; private SubsetService subsetService;
/** The short filter service. */
@Autowired
protected ShortFilterService shortFilterService;
/** /**
* Register the subset. * Register the subset.
* *
...@@ -90,14 +96,14 @@ public class SubsetRestController { ...@@ -90,14 +96,14 @@ public class SubsetRestController {
} }
/** /**
* Delete subset. * Remove subset.
* *
* @param uuid the uuid * @param uuid the uuid
* @param version the version * @param version the version
* @return the subset * @return the subset
*/ */
@DeleteMapping(value = "/{UUID},{version}", produces = { MediaType.APPLICATION_JSON_VALUE }) @DeleteMapping(value = "/{UUID},{version}", produces = { MediaType.APPLICATION_JSON_VALUE })
public Subset delete(@PathVariable("UUID") final UUID uuid, @PathVariable("version") final int version) { public Subset remove(@PathVariable("UUID") final UUID uuid, @PathVariable("version") final int version) {
return subsetService.delete(subsetService.get(uuid, version)); return subsetService.delete(subsetService.get(uuid, version));
} }
...@@ -110,13 +116,22 @@ public class SubsetRestController { ...@@ -110,13 +116,22 @@ public class SubsetRestController {
* @param sort the sort * @param sort the sort
* @param filter the filter * @param filter the filter
* @return the page * @return the page
* @throws IOException
*/ */
@PostMapping(value = "/list", produces = { MediaType.APPLICATION_JSON_VALUE }) @PostMapping(value = "/list", produces = { MediaType.APPLICATION_JSON_VALUE })
public Page<Subset> list(@RequestParam(name = "p", required = false, defaultValue = "0") final int page, public FilteredPage<Subset> list(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
@RequestParam(name = "l", required = false, defaultValue = "50") final int pageSize, @RequestParam(name = "l", required = false, defaultValue = "50") final int pageSize,
@RequestParam(name = "d", required = false, defaultValue = "ASC") final Sort.Direction direction, @RequestParam(name = "d", required = false, defaultValue = "ASC") final Sort.Direction direction,
@RequestParam(name = "s", required = false, defaultValue = "id") final String[] sort, @RequestBody final SubsetFilter filter) { @RequestParam(name = "s", required = false, defaultValue = "id") final String[] sort,
return subsetService.list(filter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort)); @RequestParam(name = "f", required = false) String filterCode,
@RequestBody(required = false) SubsetFilter filter) throws IOException {
if (filterCode != null) {
filter = shortFilterService.filterByCode(filterCode, SubsetFilter.class);
} else {
filterCode = shortFilterService.getCode(filter);
}
return new FilteredPage<>(filterCode, filter, subsetService.list(filter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort)));
} }
/** /**
......
...@@ -37,7 +37,7 @@ import java.util.UUID; ...@@ -37,7 +37,7 @@ import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.elasticsearch.common.collect.Lists; import org.elasticsearch.common.collect.Lists;
import org.genesys2.server.api.v1.SubsetRestController; import org.genesys2.server.api.v1.SubsetController;
import org.genesys2.server.model.genesys.Accession; import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionId; import org.genesys2.server.model.genesys.AccessionId;
import org.genesys2.server.model.genesys.Taxonomy2; import org.genesys2.server.model.genesys.Taxonomy2;
...@@ -137,7 +137,7 @@ public class SubsetRestControllerTest extends AbstractRestTest { ...@@ -137,7 +137,7 @@ public class SubsetRestControllerTest extends AbstractRestTest {
final String s = verboseMapper.writeValueAsString(setUpSubset()); final String s = verboseMapper.writeValueAsString(setUpSubset());
/*@formatter:off*/ /*@formatter:off*/
mockMvc.perform(post(SubsetRestController.API_BASE + "/create") mockMvc.perform(post(SubsetController.API_BASE + "/create")
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.content(s)) .content(s))
// .andDo(MockMvcResultHandlers.print()) // .andDo(MockMvcResultHandlers.print())
...@@ -172,7 +172,7 @@ public class SubsetRestControllerTest extends AbstractRestTest { ...@@ -172,7 +172,7 @@ public class SubsetRestControllerTest extends AbstractRestTest {
final String s = verboseMapper.writeValueAsString(storedSubset); final String s = verboseMapper.writeValueAsString(storedSubset);
/*@formatter:off*/ /*@formatter:off*/
mockMvc.perform(post(SubsetRestController.API_BASE + "/update") mockMvc.perform(post(SubsetController.API_BASE + "/update")
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.content(s)) .content(s))
// .andDo(MockMvcResultHandlers.print()) // .andDo(MockMvcResultHandlers.print())
...@@ -190,7 +190,7 @@ public class SubsetRestControllerTest extends AbstractRestTest { ...@@ -190,7 +190,7 @@ public class SubsetRestControllerTest extends AbstractRestTest {
final Subset subset = subsetService.create(setUpSubset()); final Subset subset = subsetService.create(setUpSubset());
/*@formatter:off*/ /*@formatter:off*/
mockMvc.perform(get(SubsetRestController.API_BASE.concat("/{UUID}"), subset.getUuid()) mockMvc.perform(get(SubsetController.API_BASE.concat("/{UUID}"), subset.getUuid())
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
// .andDo(MockMvcResultHandlers.print()) // .andDo(MockMvcResultHandlers.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
...@@ -204,7 +204,7 @@ public class SubsetRestControllerTest extends AbstractRestTest { ...@@ -204,7 +204,7 @@ public class SubsetRestControllerTest extends AbstractRestTest {
final Subset subset = subsetService.create(setUpSubset()); final Subset subset = subsetService.create(setUpSubset());
/*@formatter:off*/ /*@formatter:off*/
mockMvc.perform(delete(SubsetRestController.API_BASE.concat("/{UUID},{version}"), subset.getUuid(), subset.getVersion()) mockMvc.perform(delete(SubsetController.API_BASE.concat("/{UUID},{version}"), subset.getUuid(), subset.getVersion())
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
// .andDo(MockMvcResultHandlers.print()) // .andDo(MockMvcResultHandlers.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
...@@ -221,7 +221,7 @@ public class SubsetRestControllerTest extends AbstractRestTest { ...@@ -221,7 +221,7 @@ public class SubsetRestControllerTest extends AbstractRestTest {
subsetFilter.published = true; subsetFilter.published = true;
/*@formatter:off*/ /*@formatter:off*/
mockMvc.perform(post(SubsetRestController.API_BASE.concat("/list")) mockMvc.perform(post(SubsetController.API_BASE.concat("/list"))
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(subsetFilter))) .content(objectMapper.writeValueAsString(subsetFilter)))
// .andDo(MockMvcResultHandlers.print()) // .andDo(MockMvcResultHandlers.print())
...@@ -240,7 +240,7 @@ public class SubsetRestControllerTest extends AbstractRestTest { ...@@ -240,7 +240,7 @@ public class SubsetRestControllerTest extends AbstractRestTest {
final Set<UUID> accessionsUuid = subset.getAccessionIds().stream().map(AccessionId::getUuid).collect(Collectors.toSet()); final Set<UUID> accessionsUuid = subset.getAccessionIds().stream().map(AccessionId::getUuid).collect(Collectors.toSet());
/*@formatter:off*/ /*@formatter:off*/
mockMvc.perform(post(SubsetRestController.API_BASE.concat("/remove-accessions/{UUID},{version}"), subset.getUuid(), subset.getVersion()) mockMvc.perform(post(SubsetController.API_BASE.concat("/remove-accessions/{UUID},{version}"), subset.getUuid(), subset.getVersion())
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(accessionsUuid))) .content(objectMapper.writeValueAsString(accessionsUuid)))
// .andDo(MockMvcResultHandlers.print()) // .andDo(MockMvcResultHandlers.print())
...@@ -261,7 +261,7 @@ public class SubsetRestControllerTest extends AbstractRestTest { ...@@ -261,7 +261,7 @@ public class SubsetRestControllerTest extends AbstractRestTest {
final Set<UUID> accessionsUuid = newAccessions.stream().map(AccessionId::getUuid).collect(Collectors.toSet()); final Set<UUID> accessionsUuid = newAccessions.stream().map(AccessionId::getUuid).collect(Collectors.toSet());
/*@formatter:off*/ /*@formatter:off*/
mockMvc.perform(post(SubsetRestController.API_BASE.concat("/add-accessions/{UUID},{version}"), subset.getUuid(), subset.getVersion()) mockMvc.perform(post(SubsetController.API_BASE.concat("/add-accessions/{UUID},{version}"), subset.getUuid(), subset.getVersion())
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(accessionsUuid))) .content(objectMapper.writeValueAsString(accessionsUuid)))
// .andDo(MockMvcResultHandlers.print()) // .andDo(MockMvcResultHandlers.print())
......
...@@ -50,8 +50,9 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; ...@@ -50,8 +50,9 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration @Configuration
@PropertySource("classpath:/spring/spring.properties") @PropertySource("classpath:/spring/spring.properties")
@EnableJpaRepositories(basePackages = { "org.genesys.blocks.persistence", "org.genesys.blocks.security.persistence","org.genesys.blocks.oauth.persistence", "org.genesys.filerepository.persistence", "org.genesys2.server.persistence.acl", "org.genesys2.server.persistence", @EnableJpaRepositories(basePackages = { "org.genesys.blocks.persistence", "org.genesys.blocks.security.persistence", "org.genesys.blocks.oauth.persistence",
"org.genesys2.server.filerepository.persistence" }, repositoryImplementationPostfix = "CustomImpl", entityManagerFactoryRef = "entityManagerFactory", transactionManagerRef = "transactionManager") "org.genesys.blocks.auditlog.persistence", "org.genesys2.server.persistence", "org.genesys2.server.persistence.acl",
"org.genesys.filerepository.persistence", "org.genesys.catalog.persistence" }, entityManagerFactoryRef = "entityManagerFactory", transactionManagerRef = "transactionManager", repositoryImplementationPostfix = "CustomImpl")
@EnableTransactionManagement @EnableTransactionManagement
public class JpaDataConfig { public class JpaDataConfig {
@Autowired @Autowired
...@@ -80,7 +81,8 @@ public class JpaDataConfig { ...@@ -80,7 +81,8 @@ public class JpaDataConfig {
bean.setDataSource(dataSource()); bean.setDataSource(dataSource());
bean.setPersistenceUnitName("spring-jpa"); bean.setPersistenceUnitName("spring-jpa");
bean.setPackagesToScan("org.genesys.blocks.model", "org.genesys.blocks.security.model", "org.genesys.blocks.oauth.model", "org.genesys2.server.model", "org.genesys.filerepository.model"); bean.setPackagesToScan("org.genesys.blocks.model", "org.genesys.blocks.auditlog.model", "org.genesys.blocks.security.model",
"org.genesys.blocks.oauth.model", "org.genesys2.server.model", "org.genesys.filerepository.model", "org.genesys.catalog.model");
bean.setPersistenceProvider(new HibernatePersistenceProvider()); bean.setPersistenceProvider(new HibernatePersistenceProvider());
final HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter(); final HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
......
...@@ -36,6 +36,8 @@ import org.genesys.blocks.security.service.CustomAclService; ...@@ -36,6 +36,8 @@ import org.genesys.blocks.security.service.CustomAclService;
import org.genesys.blocks.security.service.PasswordPolicy; import org.genesys.blocks.security.service.PasswordPolicy;
import org.genesys.blocks.security.service.impl.CustomAclServiceImpl; import org.genesys.blocks.security.service.impl.CustomAclServiceImpl;
import org.genesys.blocks.security.service.impl.SimplePasswordPolicy; import org.genesys.blocks.security.service.impl.SimplePasswordPolicy;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys.catalog.service.impl.ShortFilterServiceImpl;
import org.genesys.filerepository.persistence.RepositoryFilePersistence; import org.genesys.filerepository.persistence.RepositoryFilePersistence;
import org.genesys.filerepository.service.BytesStorageService; import org.genesys.filerepository.service.BytesStorageService;
import org.genesys.filerepository.service.ImageGalleryService; import org.genesys.filerepository.service.ImageGalleryService;
...@@ -60,7 +62,7 @@ import org.genesys2.server.api.v0.PermissionController; ...@@ -60,7 +62,7 @@ import org.genesys2.server.api.v0.PermissionController;
import org.genesys2.server.api.v0.RequestsController; import org.genesys2.server.api.v0.RequestsController;
import org.genesys2.server.api.v0.TraitsController; import org.genesys2.server.api.v0.TraitsController;
import org.genesys2.server.api.v0.UsersController; import org.genesys2.server.api.v0.UsersController;
import org.genesys2.server.api.v1.SubsetRestController; import org.genesys2.server.api.v1.SubsetController;
import org.genesys2.server.aspect.AsAdminAspect; import org.genesys2.server.aspect.AsAdminAspect;
import org.genesys2.server.aspect.GenesysImageGalleryAspects; import org.genesys2.server.aspect.GenesysImageGalleryAspects;
import org.genesys2.server.mvc.admin.OAuthManagementController; import org.genesys2.server.mvc.admin.OAuthManagementController;
...@@ -235,10 +237,15 @@ public abstract class AbstractRestTest extends BaseSpringTest { ...@@ -235,10 +237,15 @@ public abstract class AbstractRestTest extends BaseSpringTest {
fsss.setRepositoryBaseDirectory(new File("data/repository")); fsss.setRepositoryBaseDirectory(new File("data/repository"));
return fsss; return fsss;
} }
@Bean
public ShortFilterService shortFilterService() {
return new ShortFilterServiceImpl();
}
@Bean @Bean
public SubsetRestController subsetRestController() { public SubsetController subsetController() {
return new SubsetRestController(); return new SubsetController();
} }
@Bean @Bean
......
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