mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
D4CRIS-336 try to inject body request parameter
This commit is contained in:
@@ -26,6 +26,7 @@ import org.dspace.app.rest.exception.PaginationException;
|
||||
import org.dspace.app.rest.exception.RepositoryNotFoundException;
|
||||
import org.dspace.app.rest.exception.RepositorySearchMethodNotFoundException;
|
||||
import org.dspace.app.rest.exception.RepositorySearchNotFoundException;
|
||||
import org.dspace.app.rest.model.QueryObject;
|
||||
import org.dspace.app.rest.model.LinkRest;
|
||||
import org.dspace.app.rest.model.RestModel;
|
||||
import org.dspace.app.rest.model.hateoas.DSpaceResource;
|
||||
@@ -47,6 +48,7 @@ import org.springframework.hateoas.PagedResources;
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
@@ -130,26 +132,34 @@ public class RestResourceController implements InitializingBean {
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{id:\\d+}/{rel}")
|
||||
public ResourceSupport findRel(HttpServletRequest request, @PathVariable String apiCategory,
|
||||
@PathVariable String model, @PathVariable Integer id, @PathVariable String rel, Pageable page,
|
||||
PagedResourcesAssembler assembler, @RequestParam(required = false) String projection) {
|
||||
return findRelInternal(request, apiCategory, model, id, rel, page, assembler, projection);
|
||||
PagedResourcesAssembler assembler, @RequestParam(required = false) String projection, @RequestBody(required = false) QueryObject data) {
|
||||
return findRelInternal(request, apiCategory, model, id, rel, page, assembler, projection, data);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{id:[A-z0-9]+}/{rel}")
|
||||
public ResourceSupport findRel(HttpServletRequest request, @PathVariable String apiCategory,
|
||||
@PathVariable String model, @PathVariable String id, @PathVariable String rel, Pageable page,
|
||||
PagedResourcesAssembler assembler, @RequestParam(required = false) String projection) {
|
||||
return findRelInternal(request, apiCategory, model, id, rel, page, assembler, projection);
|
||||
PagedResourcesAssembler assembler, @RequestParam(required = false) String projection, @RequestBody(required = false) QueryObject data) {
|
||||
return findRelInternal(request, apiCategory, model, id, rel, page, assembler, projection, data);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{uuid:[0-9a-fxA-FX]{8}-[0-9a-fxA-FX]{4}-[0-9a-fxA-FX]{4}-[0-9a-fxA-FX]{4}-[0-9a-fxA-FX]{12}}/{rel}")
|
||||
public ResourceSupport findRel(HttpServletRequest request, @PathVariable String apiCategory,
|
||||
@PathVariable String model, @PathVariable UUID uuid, @PathVariable String rel, Pageable page,
|
||||
PagedResourcesAssembler assembler, @RequestParam(required = false) String projection) {
|
||||
return findRelInternal(request, apiCategory, model, uuid, rel, page, assembler, projection);
|
||||
PagedResourcesAssembler assembler, @RequestParam(required = false) String projection, @RequestBody(required = false) QueryObject data) {
|
||||
return findRelInternal(request, apiCategory, model, uuid, rel, page, assembler, projection, data);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{id:[A-z0-9]+}/{rel}/{relid:[A-z0-9]+}")
|
||||
public ResourceSupport findRel(HttpServletRequest request, @PathVariable String apiCategory,
|
||||
@PathVariable String model, @PathVariable String id, @PathVariable String rel, @PathVariable String relid,
|
||||
Pageable page, PagedResourcesAssembler assembler, @RequestParam(required = false) String projection) {
|
||||
//return findRelEntryInternal(request, apiCategory, model, id, rel, relid, page, assembler, projection);
|
||||
return null;
|
||||
}
|
||||
|
||||
private <ID extends Serializable> ResourceSupport findRelInternal(HttpServletRequest request, String apiCategory,
|
||||
String model, ID uuid, String rel, Pageable page, PagedResourcesAssembler assembler, String projection) {
|
||||
String model, ID uuid, String rel, Pageable page, PagedResourcesAssembler assembler, String projection, QueryObject data) {
|
||||
checkModelPluralForm(apiCategory, model);
|
||||
DSpaceRestRepository<RestModel, ID> repository = utils.getResourceRepository(apiCategory, model);
|
||||
Class<RestModel> domainClass = repository.getDomainClass();
|
||||
@@ -162,12 +172,19 @@ public class RestResourceController implements InitializingBean {
|
||||
|
||||
if (linkMethod == null) {
|
||||
// TODO custom exception
|
||||
throw new RuntimeException("Method for relation " + rel + " not found: " + linkRest.name());
|
||||
throw new RuntimeException("Method for relation " + rel + " not found: " + linkRest.name() + ":" + linkRest.method());
|
||||
}
|
||||
else {
|
||||
try {
|
||||
Page<? extends Serializable> pageResult = (Page<? extends RestModel>) linkMethod
|
||||
Page<? extends Serializable> pageResult = null;
|
||||
if(data==null) {
|
||||
pageResult = (Page<? extends RestModel>) linkMethod
|
||||
.invoke(linkRepository, request, uuid, page, projection);
|
||||
}
|
||||
else {
|
||||
pageResult = (Page<? extends RestModel>) linkMethod
|
||||
.invoke(linkRepository, request, uuid, page, projection, data);
|
||||
}
|
||||
Link link = linkTo(this.getClass(), apiCategory, English.plural(model)).slash(uuid)
|
||||
.slash(rel).withSelfRel();
|
||||
PagedResources<? extends ResourceSupport> result = assembler
|
||||
|
@@ -0,0 +1,26 @@
|
||||
package org.dspace.app.rest.model;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class QueryObject {
|
||||
|
||||
private String query;
|
||||
|
||||
private Map<String, String> map;
|
||||
|
||||
public String getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
public void setQuery(String query) {
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
public Map<String, String> getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
public void setMap(Map<String, String> map) {
|
||||
this.map = map;
|
||||
}
|
||||
}
|
@@ -2,8 +2,21 @@ package org.dspace.app.rest.model.hateoas;
|
||||
|
||||
import org.dspace.app.rest.model.AuthorityEntryRest;
|
||||
import org.dspace.app.rest.model.hateoas.annotations.RelNameDSpaceResource;
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonUnwrapped;
|
||||
|
||||
@RelNameDSpaceResource(AuthorityEntryRest.NAME)
|
||||
public class AuthorityEntryResource {
|
||||
|
||||
public class AuthorityEntryResource extends ResourceSupport {
|
||||
|
||||
@JsonUnwrapped
|
||||
private final AuthorityEntryRest data;
|
||||
|
||||
public AuthorityEntryResource(AuthorityEntryRest entry) {
|
||||
this.data = entry;
|
||||
}
|
||||
|
||||
public AuthorityEntryRest getData() {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
@@ -8,7 +8,6 @@
|
||||
package org.dspace.app.rest.model.hateoas;
|
||||
|
||||
import org.dspace.app.rest.model.AuthorityRest;
|
||||
import org.dspace.app.rest.model.SubmissionDefinitionRest;
|
||||
import org.dspace.app.rest.model.hateoas.annotations.RelNameDSpaceResource;
|
||||
import org.dspace.app.rest.utils.Utils;
|
||||
|
||||
@@ -21,7 +20,8 @@ import org.dspace.app.rest.utils.Utils;
|
||||
*/
|
||||
@RelNameDSpaceResource(AuthorityRest.NAME)
|
||||
public class AuthorityResource extends DSpaceResource<AuthorityRest> {
|
||||
public AuthorityResource(AuthorityRest sd, Utils utils, String... rels) {
|
||||
public AuthorityResource(AuthorityRest sd, Utils utils, String... rels) {
|
||||
super(sd, utils, rels);
|
||||
add(utils.linkToSubResource(sd, AuthorityRest.ENTRIES));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.app.rest.repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.dspace.app.rest.model.AuthorityEntryRest;
|
||||
import org.dspace.app.rest.model.AuthorityRest;
|
||||
import org.dspace.app.rest.model.QueryObject;
|
||||
import org.dspace.app.rest.model.hateoas.AuthorityEntryResource;
|
||||
import org.dspace.app.rest.utils.AuthorityUtils;
|
||||
import org.dspace.core.Context;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Controller for exposition of authority services
|
||||
*
|
||||
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
||||
*
|
||||
*/
|
||||
@Component(AuthorityRest.CATEGORY + "." + AuthorityRest.NAME + "." + AuthorityRest.ENTRIES)
|
||||
public class AuthorityEntryLinkRepository extends AbstractDSpaceRestRepository
|
||||
implements LinkRestRepository<AuthorityEntryRest> {
|
||||
|
||||
@Autowired
|
||||
private AuthorityUtils authorityUtils;
|
||||
|
||||
@Override
|
||||
public ResourceSupport wrapResource(AuthorityEntryRest model, String... rels) {
|
||||
return new AuthorityEntryResource(model);
|
||||
}
|
||||
|
||||
public Page<AuthorityEntryRest> listAuthorityEntries(HttpServletRequest request, String name,
|
||||
Pageable pageable, String projection) {
|
||||
Context context = obtainContext();
|
||||
List<AuthorityEntryRest> authorities = authorityUtils.query(name, "", null, pageable.getOffset(), pageable.getPageSize(), context.getCurrentLocale());
|
||||
return new PageImpl<AuthorityEntryRest>(authorities, pageable, authorities.size());
|
||||
}
|
||||
|
||||
public Page<AuthorityEntryRest> listAuthorityEntries(HttpServletRequest request, String name,
|
||||
Pageable pageable, String projection, QueryObject query) {
|
||||
Context context = obtainContext();
|
||||
List<AuthorityEntryRest> authorities = authorityUtils.query(name, query.getQuery(), null, pageable.getOffset(), pageable.getPageSize(), context.getCurrentLocale());
|
||||
return new PageImpl<AuthorityEntryRest>(authorities, pageable, authorities.size());
|
||||
}
|
||||
}
|
@@ -1,33 +0,0 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.app.rest.repository;
|
||||
|
||||
import org.dspace.app.rest.model.AuthorityEntryRest;
|
||||
import org.dspace.app.rest.model.AuthorityRest;
|
||||
import org.dspace.content.authority.factory.ContentAuthorityServiceFactory;
|
||||
import org.dspace.content.authority.service.ChoiceAuthorityService;
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Controller for exposition of authority services
|
||||
*
|
||||
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
||||
*
|
||||
*/
|
||||
@Component(AuthorityRest.CATEGORY + "." + AuthorityRest.NAME + "." + AuthorityRest.ENTRIES)
|
||||
public class AuthorityEntryRestRepository extends AbstractDSpaceRestRepository
|
||||
implements LinkRestRepository<AuthorityEntryRest> {
|
||||
|
||||
@Override
|
||||
public ResourceSupport wrapResource(AuthorityEntryRest model, String... rels) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@@ -9,11 +9,16 @@ package org.dspace.app.rest.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dspace.app.rest.model.AuthorityEntryRest;
|
||||
import org.dspace.app.rest.model.AuthorityRest;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.authority.Choice;
|
||||
import org.dspace.content.authority.Choices;
|
||||
import org.dspace.content.authority.factory.ContentAuthorityServiceFactory;
|
||||
import org.dspace.content.authority.service.ChoiceAuthorityService;
|
||||
import org.dspace.content.authority.service.MetadataAuthorityService;
|
||||
@@ -93,4 +98,18 @@ public class AuthorityUtils {
|
||||
return schema + separator + element + separator + qualifier;
|
||||
}
|
||||
}
|
||||
|
||||
public List<AuthorityEntryRest> query(String name, String query, Collection collection, int start, int limit, Locale locale) {
|
||||
List<AuthorityEntryRest> result = new ArrayList<AuthorityEntryRest>();
|
||||
String metadata = cas.getChoiceMetadatabyAuthorityName(name);
|
||||
String[] tokens = tokenize(metadata);
|
||||
Choices choice = cas.getMatches(standardize(tokens[0], tokens[1], tokens[2], "_"), query, collection, start, limit, locale.toString());
|
||||
for(Choice value : choice.values) {
|
||||
AuthorityEntryRest rr = new AuthorityEntryRest();
|
||||
rr.setValue(value.value);
|
||||
rr.setCount(choice.total);
|
||||
result.add(rr);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user