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 {
* @return the api error
*/
@ResponseStatus(code = HttpStatus.NOT_FOUND)
@ExceptionHandler(NotFoundElement.class)
@ExceptionHandler(value = { NotFoundElement.class, org.genesys2.server.exception.NotFoundElement.class })
@ResponseBody
public ApiError<Exception> handleNotFound(final Exception e, final HttpServletRequest request) {
LOG.warn("Element not found {} {}", request.getMethod(), request.getRequestURL(), e);
......
......@@ -21,6 +21,7 @@ package org.genesys.catalog.exceptions;
*
* @author Andrey Lugovskoy.
*/
// TODO Replace with org.genesys2.server.api.NotFoundElement
public class NotFoundElement extends InvalidApiUsageException {
private static final long serialVersionUID = 6621976491018091330L;
......
......@@ -16,14 +16,16 @@
package org.genesys2.server.api.v1;
import java.io.IOException;
import java.util.Set;
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.service.SubsetService;
import org.genesys2.server.service.filter.SubsetFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType;
......@@ -40,15 +42,15 @@ import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
/**
* The Class SubsetRestController.
* The Class SubsetController.
*
* @author Maxym Borodenko
*/
@RestController("subsetApi1")
@PreAuthorize("isAuthenticated()")
@RequestMapping(SubsetRestController.API_BASE)
@RequestMapping(SubsetController.API_BASE)
@Api(tags = { "subset" })
public class SubsetRestController {
public class SubsetController {
/** The Constant API_BASE. */
public static final String API_BASE = "/api/v1/subset";
......@@ -56,6 +58,10 @@ public class SubsetRestController {
@Autowired
private SubsetService subsetService;
/** The short filter service. */
@Autowired
protected ShortFilterService shortFilterService;
/**
* Register the subset.
*
......@@ -90,14 +96,14 @@ public class SubsetRestController {
}
/**
* Delete subset.
* Remove subset.
*
* @param uuid the uuid
* @param version the version
* @return the subset
*/
@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));
}
......@@ -110,13 +116,22 @@ public class SubsetRestController {
* @param sort the sort
* @param filter the filter
* @return the page
* @throws IOException
*/
@PostMapping(value = "/list", produces = { MediaType.APPLICATION_JSON_VALUE })
public Page<Subset> list(@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, @RequestBody final SubsetFilter filter) {
return subsetService.list(filter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort));
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 = "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) 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;
import java.util.stream.Collectors;
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.AccessionId;
import org.genesys2.server.model.genesys.Taxonomy2;
......@@ -137,7 +137,7 @@ public class SubsetRestControllerTest extends AbstractRestTest {
final String s = verboseMapper.writeValueAsString(setUpSubset());
/*@formatter:off*/
mockMvc.perform(post(SubsetRestController.API_BASE + "/create")
mockMvc.perform(post(SubsetController.API_BASE + "/create")
.contentType(MediaType.APPLICATION_JSON)
.content(s))
// .andDo(MockMvcResultHandlers.print())
......@@ -172,7 +172,7 @@ public class SubsetRestControllerTest extends AbstractRestTest {
final String s = verboseMapper.writeValueAsString(storedSubset);
/*@formatter:off*/
mockMvc.perform(post(SubsetRestController.API_BASE + "/update")
mockMvc.perform(post(SubsetController.API_BASE + "/update")
.contentType(MediaType.APPLICATION_JSON)
.content(s))
// .andDo(MockMvcResultHandlers.print())
......@@ -190,7 +190,7 @@ public class SubsetRestControllerTest extends AbstractRestTest {
final Subset subset = subsetService.create(setUpSubset());
/*@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))
// .andDo(MockMvcResultHandlers.print())
.andExpect(status().isOk())
......@@ -204,7 +204,7 @@ public class SubsetRestControllerTest extends AbstractRestTest {
final Subset subset = subsetService.create(setUpSubset());
/*@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))
// .andDo(MockMvcResultHandlers.print())
.andExpect(status().isOk())
......@@ -221,7 +221,7 @@ public class SubsetRestControllerTest extends AbstractRestTest {
subsetFilter.published = true;
/*@formatter:off*/
mockMvc.perform(post(SubsetRestController.API_BASE.concat("/list"))
mockMvc.perform(post(SubsetController.API_BASE.concat("/list"))
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(subsetFilter)))
// .andDo(MockMvcResultHandlers.print())
......@@ -240,7 +240,7 @@ public class SubsetRestControllerTest extends AbstractRestTest {
final Set<UUID> accessionsUuid = subset.getAccessionIds().stream().map(AccessionId::getUuid).collect(Collectors.toSet());
/*@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)
.content(objectMapper.writeValueAsString(accessionsUuid)))
// .andDo(MockMvcResultHandlers.print())
......@@ -261,7 +261,7 @@ public class SubsetRestControllerTest extends AbstractRestTest {
final Set<UUID> accessionsUuid = newAccessions.stream().map(AccessionId::getUuid).collect(Collectors.toSet());
/*@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)
.content(objectMapper.writeValueAsString(accessionsUuid)))
// .andDo(MockMvcResultHandlers.print())
......
......@@ -50,8 +50,9 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@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",
"org.genesys2.server.filerepository.persistence" }, repositoryImplementationPostfix = "CustomImpl", entityManagerFactoryRef = "entityManagerFactory", transactionManagerRef = "transactionManager")
@EnableJpaRepositories(basePackages = { "org.genesys.blocks.persistence", "org.genesys.blocks.security.persistence", "org.genesys.blocks.oauth.persistence",
"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
public class JpaDataConfig {
@Autowired
......@@ -80,7 +81,8 @@ public class JpaDataConfig {
bean.setDataSource(dataSource());
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());
final HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
......
......@@ -36,6 +36,8 @@ import org.genesys.blocks.security.service.CustomAclService;
import org.genesys.blocks.security.service.PasswordPolicy;
import org.genesys.blocks.security.service.impl.CustomAclServiceImpl;
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.service.BytesStorageService;
import org.genesys.filerepository.service.ImageGalleryService;
......@@ -60,7 +62,7 @@ import org.genesys2.server.api.v0.PermissionController;
import org.genesys2.server.api.v0.RequestsController;
import org.genesys2.server.api.v0.TraitsController;
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.GenesysImageGalleryAspects;
import org.genesys2.server.mvc.admin.OAuthManagementController;
......@@ -235,10 +237,15 @@ public abstract class AbstractRestTest extends BaseSpringTest {
fsss.setRepositoryBaseDirectory(new File("data/repository"));
return fsss;
}
@Bean
public ShortFilterService shortFilterService() {
return new ShortFilterServiceImpl();
}
@Bean
public SubsetRestController subsetRestController() {
return new SubsetRestController();
public SubsetController subsetController() {
return new SubsetController();
}
@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