mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
DS-3489: Minor refactoring and code cleanup
This commit is contained in:
@@ -28,7 +28,6 @@ import org.dspace.utils.servlet.DSpaceWebappServletFilter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.servlet.ServletContextInitializer;
|
||||
@@ -46,13 +45,6 @@ import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Define the Spring Boot Application settings itself. This class takes the place
|
||||
* of a web.xml file, and configures all Filters/Listeners as methods (see below).
|
||||
@@ -93,31 +85,6 @@ public class Application extends SpringBootServletInitializer {
|
||||
.initializers(new DSpaceKernelInitializer());
|
||||
}
|
||||
|
||||
// start the kernel when the webapp starts
|
||||
try {
|
||||
this.kernelImpl = DSpaceKernelInit.getKernel(null);
|
||||
if (!this.kernelImpl.isRunning()) {
|
||||
this.kernelImpl.start(getProvidedHome(dspaceHome)); // init the kernel
|
||||
}
|
||||
|
||||
return application
|
||||
.parent(kernelImpl.getServiceManager().getApplicationContext())
|
||||
.listeners(new DSpaceKernelDestroyer(kernelImpl))
|
||||
.sources(Application.class);
|
||||
|
||||
} catch (Exception e) {
|
||||
// failed to start so destroy it and log and throw an exception
|
||||
try {
|
||||
this.kernelImpl.destroy();
|
||||
} catch (Exception e1) {
|
||||
// nothing
|
||||
}
|
||||
String message = "Failure during SpringApplicationBuilder configuration: " + e.getMessage();
|
||||
log.error(message + ":" + e.getMessage(), e);
|
||||
throw new RuntimeException(message, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ServletContextInitializer contextInitializer() {
|
||||
return servletContext -> servletContext.setInitParameter("dspace.dir", configuration.getDspaceHome());
|
||||
@@ -162,7 +129,7 @@ public class Application extends SpringBootServletInitializer {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RequestContextListener requestContextListener(){
|
||||
public RequestContextListener requestContextListener() {
|
||||
return new RequestContextListener();
|
||||
}
|
||||
|
||||
@@ -191,16 +158,16 @@ public class Application extends SpringBootServletInitializer {
|
||||
|
||||
/** Utility class that will destroy the DSpace Kernel on Spring Boot shutdown */
|
||||
private class DSpaceKernelDestroyer implements ApplicationListener<ContextClosedEvent> {
|
||||
private DSpaceKernelImpl kernelImpl;
|
||||
private DSpaceKernelImpl kernel;
|
||||
|
||||
public DSpaceKernelDestroyer(DSpaceKernelImpl kernelImpl) {
|
||||
this.kernelImpl = kernelImpl;
|
||||
public DSpaceKernelDestroyer(DSpaceKernelImpl kernel) {
|
||||
this.kernel = kernel;
|
||||
}
|
||||
|
||||
public void onApplicationEvent(final ContextClosedEvent event) {
|
||||
if (this.kernelImpl != null) {
|
||||
this.kernelImpl.destroy();
|
||||
this.kernelImpl = null;
|
||||
if (this.kernel != null) {
|
||||
this.kernel.destroy();
|
||||
this.kernel = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -208,36 +175,45 @@ public class Application extends SpringBootServletInitializer {
|
||||
/** Utility class that will initialize the DSpace Kernel on Spring Boot startup */
|
||||
private class DSpaceKernelInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||
|
||||
private transient DSpaceKernelImpl kernelImpl;
|
||||
private transient DSpaceKernel dspaceKernel;
|
||||
|
||||
public void initialize(final ConfigurableApplicationContext applicationContext) {
|
||||
|
||||
String dspaceHome = applicationContext.getEnvironment().getProperty("dspace.dir");
|
||||
|
||||
// start the kernel when the webapp starts
|
||||
try {
|
||||
this.kernelImpl = DSpaceKernelInit.getKernel(null);
|
||||
if (!this.kernelImpl.isRunning()) {
|
||||
this.kernelImpl.start(getProvidedHome(dspaceHome)); // init the kernel
|
||||
}
|
||||
this.dspaceKernel = DSpaceKernelManager.getDefaultKernel();
|
||||
if (this.dspaceKernel == null) {
|
||||
DSpaceKernelImpl kernelImpl = null;
|
||||
try {
|
||||
kernelImpl = DSpaceKernelInit.getKernel(null);
|
||||
if (!kernelImpl.isRunning()) {
|
||||
kernelImpl.start(getProvidedHome(dspaceHome)); // init the kernel
|
||||
}
|
||||
this.dspaceKernel = kernelImpl;
|
||||
|
||||
} catch (Exception e) {
|
||||
// failed to start so destroy it and log and throw an exception
|
||||
try {
|
||||
if (kernelImpl != null) {
|
||||
kernelImpl.destroy();
|
||||
}
|
||||
this.dspaceKernel = null;
|
||||
} catch (Exception e1) {
|
||||
// nothing
|
||||
}
|
||||
String message = "Failure during ServletContext initialisation: " + e.getMessage();
|
||||
log.error(message + ":" + e.getMessage(), e);
|
||||
throw new RuntimeException(message, e);
|
||||
}
|
||||
}
|
||||
|
||||
if (applicationContext.getParent() == null) {
|
||||
//Set the DSpace Kernel Application context as a parent of the Spring Boot context so that
|
||||
//we can auto-wire all DSpace Kernel services
|
||||
applicationContext.setParent(kernelImpl.getServiceManager().getApplicationContext());
|
||||
applicationContext.setParent(dspaceKernel.getServiceManager().getApplicationContext());
|
||||
|
||||
//Add a listener for Spring Boot application shutdown so that we can nicely cleanup the DSpace kernel.
|
||||
applicationContext.addApplicationListener(new DSpaceKernelDestroyer(kernelImpl));
|
||||
|
||||
} catch (Exception e) {
|
||||
// failed to start so destroy it and log and throw an exception
|
||||
try {
|
||||
this.kernelImpl.destroy();
|
||||
} catch (Exception e1) {
|
||||
// nothing
|
||||
}
|
||||
String message = "Failure during ServletContext initialisation: " + e.getMessage();
|
||||
log.error(message + ":" + e.getMessage(), e);
|
||||
throw new RuntimeException(message, e);
|
||||
applicationContext.addApplicationListener(new DSpaceKernelDestroyer((DSpaceKernelImpl) dspaceKernel));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -67,7 +67,7 @@ public class DiscoveryRestController implements InitializingBean {
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
public SearchSupportResource getSearchSupport(@RequestParam(name = "scope", required = false) String dsoScope,
|
||||
@RequestParam(name = "configuration", required = false) String configurationName){
|
||||
@RequestParam(name = "configuration", required = false) String configurationName) throws Exception {
|
||||
|
||||
SearchSupportRest searchSupportRest = discoveryRestRepository.getSearchSupport();
|
||||
SearchSupportResource searchSupportResource = new SearchSupportResource(searchSupportRest);
|
||||
@@ -77,7 +77,7 @@ public class DiscoveryRestController implements InitializingBean {
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/search")
|
||||
public SearchConfigurationResource getSearchConfiguration(@RequestParam(name = "scope", required = false) String dsoScope,
|
||||
@RequestParam(name = "configuration", required = false) String configurationName) {
|
||||
@RequestParam(name = "configuration", required = false) String configurationName) throws Exception {
|
||||
if(log.isTraceEnabled()) {
|
||||
log.trace("Retrieving search configuration for scope " + StringUtils.trimToEmpty(dsoScope)
|
||||
+ " and configuration name " + StringUtils.trimToEmpty(configurationName));
|
||||
@@ -96,7 +96,7 @@ public class DiscoveryRestController implements InitializingBean {
|
||||
@RequestParam(name = "scope", required = false) String dsoScope,
|
||||
@RequestParam(name = "configuration", required = false) String configurationName,
|
||||
List<SearchFilter> searchFilters,
|
||||
Pageable page) {
|
||||
Pageable page) throws Exception {
|
||||
if(log.isTraceEnabled()) {
|
||||
log.trace("Searching with scope: " + StringUtils.trimToEmpty(dsoScope)
|
||||
+ ", configuration name: " + StringUtils.trimToEmpty(configurationName)
|
||||
@@ -117,7 +117,7 @@ public class DiscoveryRestController implements InitializingBean {
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/facets")
|
||||
public FacetConfigurationResource getFacetsConfiguration(@RequestParam(name = "scope", required = false) String dsoScope,
|
||||
@RequestParam(name = "configuration", required = false) String configurationName) {
|
||||
@RequestParam(name = "configuration", required = false) String configurationName) throws Exception {
|
||||
if(log.isTraceEnabled()) {
|
||||
log.trace("Retrieving facet configuration for scope " + StringUtils.trimToEmpty(dsoScope)
|
||||
+ " and configuration name " + StringUtils.trimToEmpty(configurationName));
|
||||
@@ -125,6 +125,7 @@ public class DiscoveryRestController implements InitializingBean {
|
||||
|
||||
FacetConfigurationRest facetConfigurationRest = discoveryRestRepository.getFacetsConfiguration(dsoScope, configurationName);
|
||||
FacetConfigurationResource facetConfigurationResource = new FacetConfigurationResource(facetConfigurationRest);
|
||||
|
||||
halLinkService.addLinks(facetConfigurationResource);
|
||||
return facetConfigurationResource;
|
||||
}
|
||||
@@ -135,7 +136,7 @@ public class DiscoveryRestController implements InitializingBean {
|
||||
@RequestParam(name = "dsoType", required = false) String dsoType,
|
||||
@RequestParam(name = "scope", required = false) String dsoScope,
|
||||
List<SearchFilter> searchFilters,
|
||||
Pageable page) {
|
||||
Pageable page) throws Exception {
|
||||
if(log.isTraceEnabled()) {
|
||||
log.trace("Facetting on facet " + facetName + " with scope: " + StringUtils.trimToEmpty(dsoScope)
|
||||
+ ", dsoType: " + StringUtils.trimToEmpty(dsoType)
|
||||
|
@@ -7,13 +7,13 @@
|
||||
*/
|
||||
package org.dspace.app.rest;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.dspace.app.rest.link.HalLinkService;
|
||||
import org.dspace.app.rest.model.RootRest;
|
||||
import org.dspace.app.rest.model.hateoas.RootResource;
|
||||
import org.dspace.app.rest.repository.RootRestRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
@@ -7,12 +7,12 @@
|
||||
*/
|
||||
package org.dspace.app.rest.configuration;
|
||||
|
||||
import org.dspace.kernel.config.SpringLoader;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import org.dspace.kernel.config.SpringLoader;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
|
||||
/**
|
||||
* @author Kevin Van de Velde (kevin at atmire dot com)
|
||||
*/
|
||||
|
@@ -7,6 +7,9 @@
|
||||
*/
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.app.rest.model.BitstreamFormatRest;
|
||||
import org.dspace.app.rest.model.BitstreamRest;
|
||||
import org.dspace.app.rest.model.CheckSumRest;
|
||||
@@ -15,9 +18,6 @@ import org.dspace.content.Bundle;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* This is the converter from/to the Bitstream in the DSpace API data model and the REST data model
|
||||
|
@@ -7,6 +7,9 @@
|
||||
*/
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.app.rest.model.CollectionRest;
|
||||
import org.dspace.app.rest.model.CommunityRest;
|
||||
import org.dspace.content.Bitstream;
|
||||
@@ -14,9 +17,6 @@ import org.dspace.content.Collection;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is the converter from/to the community in the DSpace API data model and
|
||||
* the REST data model
|
||||
|
@@ -7,13 +7,13 @@
|
||||
*/
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.app.rest.model.MetadataEntryRest;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.content.MetadataValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* This is the base converter from/to objects in the DSpace API data model and
|
||||
|
@@ -7,6 +7,8 @@
|
||||
*/
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.dspace.app.rest.model.SearchConfigurationRest;
|
||||
import org.dspace.discovery.configuration.DiscoveryConfiguration;
|
||||
@@ -15,8 +17,6 @@ import org.dspace.discovery.configuration.DiscoverySortConfiguration;
|
||||
import org.dspace.discovery.configuration.DiscoverySortFieldConfiguration;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class' purpose is to create a SearchConfigurationRest object from the DiscoveryConfiguration to be given
|
||||
* to the convert method.
|
||||
|
@@ -7,33 +7,40 @@
|
||||
*/
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.dspace.app.rest.model.FacetConfigurationRest;
|
||||
import org.dspace.app.rest.model.SearchFacetEntryRest;
|
||||
import org.dspace.discovery.configuration.DiscoveryConfiguration;
|
||||
import org.dspace.discovery.configuration.DiscoverySearchFilterFacet;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class' purpose is to convert an object of the type DiscoveryConfiguration into a FacetConfigurationRest object
|
||||
*/
|
||||
@Component
|
||||
public class DiscoverFacetConfigurationConverter {
|
||||
public FacetConfigurationRest convert(DiscoveryConfiguration configuration){
|
||||
public FacetConfigurationRest convert(final String configurationName, final String scope, DiscoveryConfiguration configuration){
|
||||
FacetConfigurationRest facetConfigurationRest = new FacetConfigurationRest();
|
||||
|
||||
facetConfigurationRest.setConfigurationName(configurationName);
|
||||
facetConfigurationRest.setScope(scope);
|
||||
|
||||
if(configuration != null){
|
||||
addSidebarFacets(facetConfigurationRest, configuration.getSidebarFacets());
|
||||
}
|
||||
|
||||
return facetConfigurationRest;
|
||||
}
|
||||
|
||||
private void addSidebarFacets(FacetConfigurationRest facetConfigurationRest, List<DiscoverySearchFilterFacet> sidebarFacets) {
|
||||
for(DiscoverySearchFilterFacet discoverySearchFilterFacet : CollectionUtils.emptyIfNull(sidebarFacets)){
|
||||
FacetConfigurationRest.SidebarFacet sidebarFacet = new FacetConfigurationRest.SidebarFacet();
|
||||
sidebarFacet.setName(discoverySearchFilterFacet.getIndexFieldName());
|
||||
sidebarFacet.setType(discoverySearchFilterFacet.getType());
|
||||
facetConfigurationRest.addSidebarFacet(sidebarFacet);
|
||||
|
||||
SearchFacetEntryRest facetEntry = new SearchFacetEntryRest(discoverySearchFilterFacet.getIndexFieldName());
|
||||
facetEntry.setFacetType(discoverySearchFilterFacet.getType());
|
||||
|
||||
facetConfigurationRest.addSidebarFacet(facetEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -81,10 +81,8 @@ public class DiscoverFacetResultsConverter {
|
||||
facetEntryRest.setFacetType(searchResult.getFacetResult(facetName).get(0).getFieldType());
|
||||
}
|
||||
|
||||
if(searchResult.getFacetResult(facetName).size() > page.getPageSize()){
|
||||
//We requested one extra facet value. Check if that value is present to indicate that there are more results
|
||||
facetEntryRest.setHasMore(true);
|
||||
}
|
||||
//We requested one extra facet value. Check if that value is present to indicate that there are more results
|
||||
facetEntryRest.setHasMore( searchResult.getFacetResult(facetName).size() > page.getPageSize() );
|
||||
|
||||
return facetEntryRest;
|
||||
}
|
||||
|
@@ -64,6 +64,7 @@ public class DiscoverResultConverter {
|
||||
|
||||
SearchFacetEntryRest facetEntry = new SearchFacetEntryRest(field.getIndexFieldName());
|
||||
int valueCount = 0;
|
||||
facetEntry.setHasMore(false);
|
||||
|
||||
for (DiscoverResult.FacetResult value : CollectionUtils.emptyIfNull(facetValues)) {
|
||||
//The discover results contains max facetLimit + 1 values. If we reach the "+1", indicate that there are
|
||||
|
@@ -7,6 +7,9 @@
|
||||
*/
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.rest.model.EPersonRest;
|
||||
import org.dspace.app.rest.model.GroupRest;
|
||||
@@ -15,9 +18,6 @@ import org.dspace.eperson.Group;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is the converter from/to the EPerson in the DSpace API data model and the
|
||||
* REST data model
|
||||
|
@@ -7,14 +7,14 @@
|
||||
*/
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.rest.model.GroupRest;
|
||||
import org.dspace.eperson.Group;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is the converter from/to the Group in the DSpace API data model
|
||||
* and the REST data model
|
||||
|
@@ -7,6 +7,9 @@
|
||||
*/
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.rest.model.BitstreamRest;
|
||||
import org.dspace.app.rest.model.ItemRest;
|
||||
@@ -17,9 +20,6 @@ import org.dspace.content.Item;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is the converter from/to the Item in the DSpace API data model and the
|
||||
* REST data model
|
||||
|
@@ -8,8 +8,6 @@
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import org.dspace.app.rest.model.RootRest;
|
||||
import org.dspace.app.rest.utils.ApplicationConfig;
|
||||
import org.dspace.servicemanager.config.DSpaceConfigurationService;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@@ -7,8 +7,6 @@
|
||||
*/
|
||||
package org.dspace.app.rest.exception;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* This class provides an exception to be used when the SearchFilter given is invalid
|
||||
*/
|
||||
|
@@ -26,7 +26,7 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||
@Component
|
||||
public class BrowseEntryHalLinkFactory extends HalLinkFactory<BrowseEntryResource, RestResourceController> {
|
||||
|
||||
protected void addLinks(final BrowseEntryResource halResource, final Pageable pageable, final LinkedList<Link> list) {
|
||||
protected void addLinks(final BrowseEntryResource halResource, final Pageable pageable, final LinkedList<Link> list) throws Exception{
|
||||
BrowseEntryRest data = halResource.getContent();
|
||||
|
||||
if(data != null) {
|
||||
|
@@ -7,7 +7,6 @@
|
||||
*/
|
||||
package org.dspace.app.rest.link;
|
||||
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
@@ -21,6 +20,7 @@ import org.dspace.app.rest.model.RestModel;
|
||||
import org.dspace.app.rest.model.hateoas.DSpaceResource;
|
||||
import org.dspace.app.rest.utils.Utils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -33,7 +33,7 @@ public class DSpaceResourceHalLinkFactory extends HalLinkFactory<DSpaceResource,
|
||||
@Autowired
|
||||
private Utils utils;
|
||||
|
||||
protected void addLinks(DSpaceResource halResource, Pageable page, LinkedList<Link> list) {
|
||||
protected void addLinks(DSpaceResource halResource, Pageable page, LinkedList<Link> list) throws Exception {
|
||||
RestModel data = halResource.getContent();
|
||||
|
||||
try {
|
||||
|
@@ -33,7 +33,7 @@ public abstract class HalLinkFactory<RESOURCE, CONTROLLER> {
|
||||
}
|
||||
}
|
||||
|
||||
public List<Link> getLinksFor(HALResource halResource, Pageable pageable) {
|
||||
public List<Link> getLinksFor(HALResource halResource, Pageable pageable) throws Exception {
|
||||
LinkedList<Link> list = new LinkedList<>();
|
||||
|
||||
if(halResource != null && supports(halResource.getClass())){
|
||||
@@ -69,7 +69,7 @@ public abstract class HalLinkFactory<RESOURCE, CONTROLLER> {
|
||||
return methodOn(clazz);
|
||||
}
|
||||
|
||||
protected abstract void addLinks(RESOURCE halResource, Pageable pageable, LinkedList<Link> list);
|
||||
protected abstract void addLinks(RESOURCE halResource, Pageable pageable, LinkedList<Link> list) throws Exception;
|
||||
|
||||
protected abstract Class<CONTROLLER> getControllerClass();
|
||||
|
||||
|
@@ -14,6 +14,8 @@ import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.rest.model.hateoas.HALResource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
@@ -29,12 +31,14 @@ import org.springframework.stereotype.Component;
|
||||
@ComponentScan
|
||||
public class HalLinkService {
|
||||
|
||||
private static final Logger log = Logger.getLogger(HalLinkService.class);
|
||||
|
||||
@Autowired
|
||||
private List<HalLinkFactory> halLinkFactories;
|
||||
|
||||
private Map<String, List<HalLinkFactory>> cachedMappings = new ConcurrentHashMap<>();
|
||||
|
||||
public void addLinks(HALResource halResource, Pageable pageable){
|
||||
public void addLinks(HALResource halResource, Pageable pageable) throws Exception {
|
||||
LinkedList<Link> links = new LinkedList<>();
|
||||
|
||||
List<HalLinkFactory> supportedFactories = getSupportedFactories(halResource);
|
||||
@@ -42,6 +46,8 @@ public class HalLinkService {
|
||||
links.addAll(halLinkFactory.getLinksFor(halResource, pageable));
|
||||
}
|
||||
|
||||
links.sort((Link l1, Link l2) -> ObjectUtils.compare(l1.getRel(), l2.getRel()));
|
||||
|
||||
halResource.add(links);
|
||||
|
||||
for (Object obj : halResource.getEmbeddedResources().values()) {
|
||||
@@ -83,7 +89,11 @@ public class HalLinkService {
|
||||
}
|
||||
|
||||
public HALResource addLinks(HALResource halResource) {
|
||||
addLinks(halResource, null);
|
||||
try {
|
||||
addLinks(halResource, null);
|
||||
} catch (Exception ex) {
|
||||
log.warn("Unable to add links to HAL resource " + halResource, ex);
|
||||
}
|
||||
return halResource;
|
||||
}
|
||||
|
||||
|
@@ -26,7 +26,7 @@ public class RootHalLinkFactory extends HalLinkFactory<RootResource, RootRestRes
|
||||
@Autowired
|
||||
DiscoverableEndpointsService discoverableEndpointsService;
|
||||
|
||||
protected void addLinks(RootResource halResource, Pageable page, LinkedList<Link> list) {
|
||||
protected void addLinks(RootResource halResource, Pageable page, LinkedList<Link> list) throws Exception {
|
||||
for(Link endpointLink : discoverableEndpointsService.getDiscoverableEndpoints()){
|
||||
list.add(buildLink(endpointLink.getRel(), halResource.getContent().getDspaceRest() + endpointLink.getHref()));
|
||||
}
|
||||
|
@@ -19,14 +19,14 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||
*/
|
||||
public abstract class DiscoveryRestHalLinkFactory<T> extends HalLinkFactory<T, DiscoveryRestController> {
|
||||
|
||||
protected UriComponentsBuilder buildSearchBaseLink(final DiscoveryResultsRest data) {
|
||||
protected UriComponentsBuilder buildSearchBaseLink(final DiscoveryResultsRest data) throws Exception {
|
||||
UriComponentsBuilder uriBuilder = uriBuilder(getMethodOn()
|
||||
.getSearchObjects(data.getQuery(), data.getDsoType(), data.getScope(), data.getConfigurationName(), null, null));
|
||||
|
||||
return addFilterParams(uriBuilder, data);
|
||||
}
|
||||
|
||||
protected UriComponentsBuilder buildFacetBaseLink(final FacetResultsRest data) {
|
||||
protected UriComponentsBuilder buildFacetBaseLink(final FacetResultsRest data) throws Exception {
|
||||
UriComponentsBuilder uriBuilder = uriBuilder(getMethodOn()
|
||||
.getFacetValues(data.getFacetEntry().getName(), data.getQuery(), data.getDsoType(), data.getScope(), null, null));
|
||||
|
||||
@@ -34,7 +34,7 @@ public abstract class DiscoveryRestHalLinkFactory<T> extends HalLinkFactory<T, D
|
||||
}
|
||||
|
||||
protected UriComponentsBuilder addFilterParams(UriComponentsBuilder uriComponentsBuilder, DiscoveryResultsRest data) {
|
||||
if (data.getAppliedFilters() != null) {
|
||||
if (uriComponentsBuilder != null && data != null && data.getAppliedFilters() != null) {
|
||||
for (SearchResultsRest.AppliedFilter filter : data.getAppliedFilters()) {
|
||||
//TODO Make sure the filter format is defined in only one place
|
||||
uriComponentsBuilder.queryParam("f." + filter.getFilter(), filter.getValue() + "," + filter.getOperator());
|
||||
|
@@ -24,7 +24,7 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class FacetConfigurationResourceHalLinkFactory extends DiscoveryRestHalLinkFactory<FacetConfigurationResource> {
|
||||
|
||||
protected void addLinks(FacetConfigurationResource halResource, Pageable page, LinkedList<Link> list) {
|
||||
protected void addLinks(FacetConfigurationResource halResource, Pageable page, LinkedList<Link> list) throws Exception {
|
||||
FacetConfigurationRest data = halResource.getContent();
|
||||
|
||||
if(data != null){
|
||||
|
@@ -25,7 +25,7 @@ import org.springframework.stereotype.Component;
|
||||
public class FacetResultsHalLinkFactory extends DiscoveryRestHalLinkFactory<FacetResultsResource> {
|
||||
|
||||
@Override
|
||||
protected void addLinks(FacetResultsResource halResource, Pageable pageable, LinkedList<Link> list) {
|
||||
protected void addLinks(FacetResultsResource halResource, Pageable pageable, LinkedList<Link> list) throws Exception {
|
||||
FacetResultsRest data = halResource.getContent();
|
||||
|
||||
if(data != null && pageable != null){
|
||||
|
@@ -24,7 +24,7 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class SearchConfigurationResourceHalLinkFactory extends HalLinkFactory<SearchConfigurationResource, DiscoveryRestController> {
|
||||
|
||||
protected void addLinks(SearchConfigurationResource halResource, Pageable pageable, LinkedList<Link> list) {
|
||||
protected void addLinks(SearchConfigurationResource halResource, Pageable pageable, LinkedList<Link> list) throws Exception {
|
||||
SearchConfigurationRest data = halResource.getContent();
|
||||
|
||||
if(data != null){
|
||||
|
@@ -7,15 +7,11 @@
|
||||
*/
|
||||
package org.dspace.app.rest.link.search;
|
||||
|
||||
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.dspace.app.rest.model.DiscoveryResultsRest;
|
||||
import org.dspace.app.rest.model.SearchFacetEntryRest;
|
||||
import org.dspace.app.rest.model.hateoas.SearchFacetEntryResource;
|
||||
import org.dspace.app.rest.model.hateoas.SearchFacetValueResource;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -27,13 +23,18 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||
*/
|
||||
@Component
|
||||
public class SearchFacetEntryHalLinkFactory extends DiscoveryRestHalLinkFactory<SearchFacetEntryResource> {
|
||||
|
||||
@Override
|
||||
protected void addLinks(SearchFacetEntryResource halResource, Pageable pageable, LinkedList<Link> list) {
|
||||
protected void addLinks(SearchFacetEntryResource halResource, Pageable pageable, LinkedList<Link> list) throws Exception {
|
||||
SearchFacetEntryRest facetData = halResource.getFacetData();
|
||||
DiscoveryResultsRest searchData = halResource.getSearchData();
|
||||
|
||||
String query = searchData == null ? null : searchData.getQuery();
|
||||
String dsoType = searchData == null ? null : searchData.getDsoType();
|
||||
String scope = searchData == null ? null : searchData.getScope();
|
||||
|
||||
UriComponentsBuilder uriBuilder = uriBuilder(getMethodOn()
|
||||
.getFacetValues(facetData.getName(), searchData.getQuery(), searchData.getDsoType(), searchData.getScope(), null, null));
|
||||
.getFacetValues(facetData.getName(), query, dsoType, scope, null, null));
|
||||
|
||||
addFilterParams(uriBuilder, searchData);
|
||||
|
||||
|
@@ -23,8 +23,9 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||
*/
|
||||
@Component
|
||||
public class SearchFacetValueHalLinkFactory extends DiscoveryRestHalLinkFactory<SearchFacetValueResource> {
|
||||
|
||||
@Override
|
||||
protected void addLinks(SearchFacetValueResource halResource, Pageable pageable, LinkedList<Link> list) {
|
||||
protected void addLinks(SearchFacetValueResource halResource, Pageable pageable, LinkedList<Link> list) throws Exception {
|
||||
|
||||
if(halResource.getSearchData() != null && halResource.getFacetData() != null && halResource.getValueData() != null){
|
||||
|
||||
|
@@ -28,7 +28,7 @@ public class SearchResultEntryHalLinkFactory extends DiscoveryRestHalLinkFactory
|
||||
private Utils utils;
|
||||
|
||||
@Override
|
||||
protected void addLinks(SearchResultEntryResource halResource, Pageable pageable, LinkedList<Link> list) {
|
||||
protected void addLinks(SearchResultEntryResource halResource, Pageable pageable, LinkedList<Link> list) throws Exception {
|
||||
SearchResultEntryRest data = halResource.getContent();
|
||||
|
||||
if(data != null && data.getDspaceObject() != null) {
|
||||
|
@@ -7,6 +7,8 @@
|
||||
*/
|
||||
package org.dspace.app.rest.link.search;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.dspace.app.rest.model.SearchResultsRest;
|
||||
import org.dspace.app.rest.model.hateoas.EmbeddedPageHeader;
|
||||
import org.dspace.app.rest.model.hateoas.SearchResultEntryResource;
|
||||
@@ -16,10 +18,6 @@ import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
|
||||
|
||||
/**
|
||||
* This class will add links to the SearchResultsResource. This method will be called when calling the higher up
|
||||
* addLinks in the HalLinkService
|
||||
@@ -27,7 +25,7 @@ import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
|
||||
@Component
|
||||
public class SearchResultsResourceHalLinkFactory extends DiscoveryRestHalLinkFactory<SearchResultsResource> {
|
||||
|
||||
protected void addLinks(SearchResultsResource halResource, Pageable pageable, LinkedList<Link> list) {
|
||||
protected void addLinks(SearchResultsResource halResource, Pageable pageable, LinkedList<Link> list) throws Exception {
|
||||
SearchResultsRest data = halResource.getContent();
|
||||
|
||||
if(data != null && pageable != null){
|
||||
|
@@ -24,7 +24,7 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class SearchSupportHalLinkFactory extends HalLinkFactory<SearchSupportResource, DiscoveryRestController> {
|
||||
|
||||
protected void addLinks(SearchSupportResource halResource, Pageable pageable, LinkedList<Link> list) {
|
||||
protected void addLinks(SearchSupportResource halResource, Pageable pageable, LinkedList<Link> list) throws Exception {
|
||||
list.add(buildLink(Link.REL_SELF, getMethodOn()
|
||||
.getSearchSupport(null, null)));
|
||||
list.add(buildLink("search", getMethodOn().getSearchConfiguration(null, null)));
|
||||
|
@@ -9,9 +9,8 @@ package org.dspace.app.rest.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.hateoas.Identifiable;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.springframework.hateoas.Identifiable;
|
||||
|
||||
/**
|
||||
* Base class for any REST resource that need to be addressable
|
||||
|
@@ -9,10 +9,9 @@ package org.dspace.app.rest.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.app.rest.RestResourceController;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.dspace.app.rest.RestResourceController;
|
||||
|
||||
/**
|
||||
* The Browse Index REST Resource
|
||||
|
@@ -7,16 +7,13 @@
|
||||
*/
|
||||
package org.dspace.app.rest.model;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.apache.commons.codec.binary.StringUtils;
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
import org.dspace.app.rest.DiscoveryRestController;
|
||||
import org.dspace.app.rest.model.hateoas.SearchConfigurationResource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class' purpose is to give information about the FacetConfiguration to be displayed on the /facets endpoint
|
||||
@@ -25,13 +22,13 @@ public class FacetConfigurationRest extends BaseObjectRest<String> {
|
||||
|
||||
public static final String NAME = "discover";
|
||||
public static final String CATEGORY = RestModel.DISCOVER;
|
||||
@JsonIgnore
|
||||
|
||||
private String scope;
|
||||
@JsonIgnore
|
||||
|
||||
private String configurationName;
|
||||
|
||||
@JsonIgnore
|
||||
private LinkedList<SidebarFacet> sidebarFacets = new LinkedList<>();
|
||||
private LinkedList<SearchFacetEntryRest> sidebarFacets = new LinkedList<>();
|
||||
|
||||
public String getCategory() {
|
||||
return CATEGORY;
|
||||
@@ -48,6 +45,7 @@ public class FacetConfigurationRest extends BaseObjectRest<String> {
|
||||
public String getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
public void setScope(String scope){
|
||||
this.scope = scope;
|
||||
}
|
||||
@@ -55,12 +53,13 @@ public class FacetConfigurationRest extends BaseObjectRest<String> {
|
||||
public String getConfigurationName() {
|
||||
return configurationName;
|
||||
}
|
||||
|
||||
public void setConfigurationName(String configurationName){
|
||||
this.configurationName = configurationName;
|
||||
}
|
||||
|
||||
public List<SidebarFacet> getSidebarFacets(){ return sidebarFacets;}
|
||||
public void addSidebarFacet(SidebarFacet sidebarFacet){sidebarFacets.add(sidebarFacet);}
|
||||
public List<SearchFacetEntryRest> getSidebarFacets(){ return sidebarFacets;}
|
||||
public void addSidebarFacet(SearchFacetEntryRest sidebarFacet){sidebarFacets.add(sidebarFacet);}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object){
|
||||
@@ -85,26 +84,4 @@ public class FacetConfigurationRest extends BaseObjectRest<String> {
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
public static class SidebarFacet{
|
||||
private String name;
|
||||
private String type;
|
||||
public String getName(){ return name;}
|
||||
public void setName(String name){this.name=name;}
|
||||
public String getType(){ return type;}
|
||||
public void setType(String type){this.type=type;}
|
||||
@Override
|
||||
public boolean equals(Object object){
|
||||
return (object instanceof SidebarFacet &&
|
||||
new EqualsBuilder().append(this.getName(), ((SidebarFacet) object).getName())
|
||||
.isEquals());
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(this.getName())
|
||||
.toHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -9,9 +9,8 @@ package org.dspace.app.rest.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.app.rest.RestResourceController;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.dspace.app.rest.RestResourceController;
|
||||
|
||||
/**
|
||||
* The Group REST Resource
|
||||
|
@@ -11,8 +11,6 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty.Access;
|
||||
|
||||
/**
|
||||
* The Item REST Resource
|
||||
|
@@ -7,9 +7,8 @@
|
||||
*/
|
||||
package org.dspace.app.rest.model;
|
||||
|
||||
import org.dspace.app.rest.RestResourceController;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.dspace.app.rest.RestResourceController;
|
||||
|
||||
/**
|
||||
* The MetadataField REST Resource
|
||||
|
@@ -7,12 +7,8 @@
|
||||
*/
|
||||
package org.dspace.app.rest.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.app.rest.RestResourceController;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
/**
|
||||
* The MetadataSchema REST Resource
|
||||
*
|
||||
|
@@ -10,11 +10,6 @@ package org.dspace.app.rest.model;
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
import org.dspace.kernel.DSpaceKernel;
|
||||
import org.dspace.servicemanager.DSpaceServiceManager;
|
||||
import org.dspace.servicemanager.config.DSpaceConfigurationService;
|
||||
|
||||
/**
|
||||
* Methods to implement to make a REST resource addressable
|
||||
|
@@ -7,16 +7,13 @@
|
||||
*/
|
||||
package org.dspace.app.rest.model;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.apache.commons.codec.binary.StringUtils;
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
import org.dspace.app.rest.DiscoveryRestController;
|
||||
import org.dspace.app.rest.model.hateoas.SearchConfigurationResource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class' purpose is to store the information that'll be shown on the /search endpoint.
|
||||
|
@@ -7,12 +7,13 @@
|
||||
*/
|
||||
package org.dspace.app.rest.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.dspace.app.rest.DiscoveryRestController;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import org.dspace.app.rest.DiscoveryRestController;
|
||||
|
||||
/**
|
||||
* This class' purpose is to create a container for the information used in the SearchFacetEntryResource
|
||||
*/
|
||||
@@ -23,7 +24,7 @@ public class SearchFacetEntryRest implements RestModel {
|
||||
|
||||
private String name;
|
||||
private String facetType;
|
||||
private boolean hasMore = false;
|
||||
private Boolean hasMore = null;
|
||||
|
||||
@JsonIgnore
|
||||
private List<SearchFacetValueRest> values;
|
||||
@@ -73,11 +74,12 @@ public class SearchFacetEntryRest implements RestModel {
|
||||
this.facetType = facetType;
|
||||
}
|
||||
|
||||
public void setHasMore(final boolean hasMore) {
|
||||
public void setHasMore(final Boolean hasMore) {
|
||||
this.hasMore = hasMore;
|
||||
}
|
||||
|
||||
public boolean isHasMore() {
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
public Boolean isHasMore() {
|
||||
return hasMore;
|
||||
}
|
||||
}
|
||||
|
@@ -7,13 +7,13 @@
|
||||
*/
|
||||
package org.dspace.app.rest.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.dspace.app.rest.DiscoveryRestController;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.dspace.app.rest.DiscoveryRestController;
|
||||
|
||||
/**
|
||||
* This class' purpose is to create a container for the information in the SearchResultEntryResource
|
||||
*/
|
||||
|
@@ -7,15 +7,13 @@
|
||||
*/
|
||||
package org.dspace.app.rest.model.hateoas;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.dspace.app.rest.model.DiscoveryResultsRest;
|
||||
import org.dspace.app.rest.model.FacetConfigurationRest;
|
||||
import org.dspace.app.rest.model.SearchFacetEntryRest;
|
||||
import org.dspace.app.rest.model.SearchResultsRest;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.dspace.app.rest.model.FacetConfigurationRest;
|
||||
import org.dspace.app.rest.model.SearchFacetEntryRest;
|
||||
|
||||
/**
|
||||
* This class' purpose is to provide a resource with the information, links and embeds for the /facet endpoint
|
||||
*/
|
||||
@@ -28,15 +26,12 @@ public class FacetConfigurationResource extends HALResource<FacetConfigurationRe
|
||||
|
||||
public void addEmbeds(FacetConfigurationRest data) {
|
||||
List<SearchFacetEntryResource> searchFacetEntryResources = new LinkedList<>();
|
||||
List<FacetConfigurationRest.SidebarFacet> facets = data.getSidebarFacets();
|
||||
for (FacetConfigurationRest.SidebarFacet field : CollectionUtils.emptyIfNull(facets)) {
|
||||
|
||||
SearchFacetEntryRest facetEntry = new SearchFacetEntryRest(field.getName());
|
||||
facetEntry.setFacetType(field.getType());
|
||||
DiscoveryResultsRest discoveryResultsRest = new SearchResultsRest();
|
||||
SearchFacetEntryResource searchFacetEntryResource = new SearchFacetEntryResource(facetEntry, discoveryResultsRest );
|
||||
for (SearchFacetEntryRest facetEntry : CollectionUtils.emptyIfNull(data.getSidebarFacets())) {
|
||||
SearchFacetEntryResource searchFacetEntryResource = new SearchFacetEntryResource(facetEntry);
|
||||
searchFacetEntryResources.add(searchFacetEntryResource);
|
||||
}
|
||||
|
||||
embedResource("facets", searchFacetEntryResources);
|
||||
}
|
||||
|
||||
|
@@ -31,6 +31,10 @@ public class SearchFacetEntryResource extends HALResource<SearchFacetEntryRest>
|
||||
addEmbeds();
|
||||
}
|
||||
|
||||
public SearchFacetEntryResource(final SearchFacetEntryRest facetData) {
|
||||
this(facetData, null);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public SearchFacetEntryRest getFacetData() {
|
||||
return getContent();
|
||||
@@ -41,13 +45,15 @@ public class SearchFacetEntryResource extends HALResource<SearchFacetEntryRest>
|
||||
}
|
||||
|
||||
private void addEmbeds() {
|
||||
List<SearchFacetValueResource> valueResourceList = new LinkedList<>();
|
||||
if(searchData != null) {
|
||||
List<SearchFacetValueResource> valueResourceList = new LinkedList<>();
|
||||
|
||||
for (SearchFacetValueRest valueRest : CollectionUtils.emptyIfNull(getContent().getValues())) {
|
||||
SearchFacetValueResource valueResource = new SearchFacetValueResource(valueRest, getContent(), searchData);
|
||||
valueResourceList.add(valueResource);
|
||||
for (SearchFacetValueRest valueRest : CollectionUtils.emptyIfNull(getContent().getValues())) {
|
||||
SearchFacetValueResource valueResource = new SearchFacetValueResource(valueRest, getContent(), searchData);
|
||||
valueResourceList.add(valueResource);
|
||||
}
|
||||
|
||||
embedResource("values", valueResourceList);
|
||||
}
|
||||
|
||||
embedResource("values", valueResourceList);
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,11 @@
|
||||
*/
|
||||
package org.dspace.app.rest.parameter.resolver;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.dspace.app.rest.parameter.SearchFilter;
|
||||
import org.springframework.core.MethodParameter;
|
||||
@@ -15,11 +20,6 @@ import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Custom Request parameter resolver to fill in {@link org.dspace.app.rest.parameter.SearchFilter} parameter objects
|
||||
* TODO UNIT TEST
|
||||
|
@@ -7,6 +7,9 @@
|
||||
*/
|
||||
package org.dspace.app.rest.repository;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.app.rest.converter.BitstreamFormatConverter;
|
||||
import org.dspace.app.rest.model.BitstreamFormatRest;
|
||||
import org.dspace.app.rest.model.hateoas.BitstreamFormatResource;
|
||||
@@ -18,9 +21,6 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is the repository responsible to manage BitstreamFormat Rest object
|
||||
*
|
||||
|
@@ -7,6 +7,14 @@
|
||||
*/
|
||||
package org.dspace.app.rest.repository;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.dspace.app.rest.converter.BitstreamConverter;
|
||||
import org.dspace.app.rest.model.BitstreamRest;
|
||||
import org.dspace.app.rest.model.hateoas.BitstreamResource;
|
||||
@@ -20,14 +28,6 @@ import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* This is the repository responsible to manage Bitstream Rest object
|
||||
*
|
||||
|
@@ -7,29 +7,36 @@
|
||||
*/
|
||||
package org.dspace.app.rest.repository;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dspace.app.rest.converter.BrowseEntryConverter;
|
||||
import org.dspace.app.rest.converter.BrowseIndexConverter;
|
||||
import org.dspace.app.rest.model.BrowseEntryRest;
|
||||
import org.dspace.app.rest.model.BrowseIndexRest;
|
||||
import org.dspace.app.rest.model.hateoas.BrowseEntryResource;
|
||||
import org.dspace.browse.*;
|
||||
import org.dspace.app.rest.utils.ScopeResolver;
|
||||
import org.dspace.browse.BrowseEngine;
|
||||
import org.dspace.browse.BrowseException;
|
||||
import org.dspace.browse.BrowseIndex;
|
||||
import org.dspace.browse.BrowseInfo;
|
||||
import org.dspace.browse.BrowserScope;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.content.service.CollectionService;
|
||||
import org.dspace.content.service.CommunityService;
|
||||
import org.dspace.core.Context;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.*;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* This is the repository responsible to retrieve the first level values
|
||||
* (Entries) of a metadata browse
|
||||
@@ -47,10 +54,7 @@ public class BrowseEntryLinkRepository extends AbstractDSpaceRestRepository
|
||||
BrowseIndexConverter bixConverter;
|
||||
|
||||
@Autowired
|
||||
CollectionService collectionService;
|
||||
|
||||
@Autowired
|
||||
CommunityService communityService;
|
||||
ScopeResolver scopeResolver;
|
||||
|
||||
// FIXME It will be nice to drive arguments binding by annotation as in normal spring controller methods
|
||||
public Page<BrowseEntryRest> listBrowseEntries(HttpServletRequest request, String browseName,
|
||||
|
@@ -7,16 +7,12 @@
|
||||
*/
|
||||
package org.dspace.app.rest.repository;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.app.rest.converter.BrowseIndexConverter;
|
||||
import org.dspace.app.rest.converter.CollectionConverter;
|
||||
import org.dspace.app.rest.model.BrowseIndexRest;
|
||||
import org.dspace.app.rest.model.CollectionRest;
|
||||
import org.dspace.app.rest.model.hateoas.BrowseIndexResource;
|
||||
import org.dspace.app.rest.model.hateoas.CollectionResource;
|
||||
import org.dspace.browse.BrowseException;
|
||||
import org.dspace.browse.BrowseIndex;
|
||||
import org.dspace.core.Context;
|
||||
@@ -24,7 +20,6 @@ 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.data.rest.webmvc.ResourceNotFoundException;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
|
@@ -7,27 +7,36 @@
|
||||
*/
|
||||
package org.dspace.app.rest.repository;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dspace.app.rest.converter.ItemConverter;
|
||||
import org.dspace.app.rest.model.BrowseIndexRest;
|
||||
import org.dspace.app.rest.model.ItemRest;
|
||||
import org.dspace.app.rest.model.hateoas.ItemResource;
|
||||
import org.dspace.app.rest.utils.ScopeResolver;
|
||||
import org.dspace.browse.*;
|
||||
import org.dspace.browse.BrowseEngine;
|
||||
import org.dspace.browse.BrowseException;
|
||||
import org.dspace.browse.BrowseIndex;
|
||||
import org.dspace.browse.BrowseInfo;
|
||||
import org.dspace.browse.BrowserScope;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.sort.SortException;
|
||||
import org.dspace.sort.SortOption;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.*;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* This is the repository to retrieve the items associated with a specific
|
||||
* browse index or entries
|
||||
@@ -45,10 +54,7 @@ public class BrowseItemLinkRepository extends AbstractDSpaceRestRepository
|
||||
ItemRestRepository itemRestRepository;
|
||||
|
||||
@Autowired
|
||||
CollectionService collectionService;
|
||||
|
||||
@Autowired
|
||||
CommunityService communityService;
|
||||
ScopeResolver scopeResolver;
|
||||
|
||||
public Page<ItemRest> listBrowseItems(HttpServletRequest request, String browseName, Pageable pageable, String projection)
|
||||
throws BrowseException, SQLException {
|
||||
|
@@ -7,6 +7,11 @@
|
||||
*/
|
||||
package org.dspace.app.rest.repository;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.dspace.app.rest.converter.CollectionConverter;
|
||||
import org.dspace.app.rest.model.CollectionRest;
|
||||
import org.dspace.app.rest.model.hateoas.CollectionResource;
|
||||
@@ -23,11 +28,6 @@ import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* This is the repository responsible to manage Item Rest object
|
||||
*
|
||||
|
@@ -7,6 +7,12 @@
|
||||
*/
|
||||
package org.dspace.app.rest.repository;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.dspace.app.rest.SearchRestMethod;
|
||||
import org.dspace.app.rest.converter.CommunityConverter;
|
||||
import org.dspace.app.rest.model.CommunityRest;
|
||||
import org.dspace.app.rest.model.hateoas.CommunityResource;
|
||||
@@ -21,11 +27,6 @@ import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* This is the repository responsible to manage Item Rest object
|
||||
*
|
||||
|
@@ -11,13 +11,7 @@ import java.io.Serializable;
|
||||
|
||||
import org.dspace.app.rest.model.RestModel;
|
||||
import org.dspace.app.rest.model.hateoas.DSpaceResource;
|
||||
import org.dspace.app.rest.utils.ContextUtil;
|
||||
import org.dspace.app.rest.utils.Utils;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.services.RequestService;
|
||||
import org.dspace.services.model.Request;
|
||||
import org.dspace.utils.DSpace;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
@@ -7,12 +7,20 @@
|
||||
*/
|
||||
package org.dspace.app.rest.repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.rest.converter.*;
|
||||
import org.dspace.app.rest.converter.DiscoverConfigurationConverter;
|
||||
import org.dspace.app.rest.converter.DiscoverFacetConfigurationConverter;
|
||||
import org.dspace.app.rest.converter.DiscoverFacetResultsConverter;
|
||||
import org.dspace.app.rest.converter.DiscoverResultConverter;
|
||||
import org.dspace.app.rest.converter.DiscoverSearchSupportConverter;
|
||||
import org.dspace.app.rest.exception.InvalidRequestException;
|
||||
import org.dspace.app.rest.model.*;
|
||||
import org.dspace.app.rest.model.hateoas.SearchConfigurationResource;
|
||||
import org.dspace.app.rest.model.hateoas.SearchResultsResource;
|
||||
import org.dspace.app.rest.model.FacetConfigurationRest;
|
||||
import org.dspace.app.rest.model.FacetResultsRest;
|
||||
import org.dspace.app.rest.model.SearchConfigurationRest;
|
||||
import org.dspace.app.rest.model.SearchResultsRest;
|
||||
import org.dspace.app.rest.model.SearchSupportRest;
|
||||
import org.dspace.app.rest.parameter.SearchFilter;
|
||||
import org.dspace.app.rest.utils.DiscoverQueryBuilder;
|
||||
import org.dspace.app.rest.utils.ScopeResolver;
|
||||
@@ -25,12 +33,9 @@ import org.dspace.discovery.SearchServiceException;
|
||||
import org.dspace.discovery.configuration.DiscoveryConfiguration;
|
||||
import org.dspace.discovery.configuration.DiscoveryConfigurationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class' purpose is to return a REST object to the controller class. This repository handles all the information lookup
|
||||
* that has to be done for the endpoint
|
||||
@@ -76,7 +81,8 @@ public class DiscoveryRestRepository extends AbstractDSpaceRestRepository {
|
||||
return discoverConfigurationConverter.convert(configuration);
|
||||
}
|
||||
|
||||
public SearchResultsRest getSearchObjects(final String query, final String dsoType, final String dsoScope, final String configurationName, final List<SearchFilter> searchFilters, final Pageable page) {
|
||||
public SearchResultsRest getSearchObjects(final String query, final String dsoType, final String dsoScope, final String configurationName,
|
||||
final List<SearchFilter> searchFilters, final Pageable page) throws InvalidRequestException {
|
||||
Context context = obtainContext();
|
||||
|
||||
DSpaceObject scopeObject = scopeResolver.resolveScope(context, dsoScope);
|
||||
@@ -89,8 +95,6 @@ public class DiscoveryRestRepository extends AbstractDSpaceRestRepository {
|
||||
discoverQuery = queryBuilder.buildQuery(context, scopeObject, configuration, query, searchFilters, dsoType, page);
|
||||
searchResult = searchService.search(context, scopeObject, discoverQuery);
|
||||
|
||||
} catch (InvalidRequestException e) {
|
||||
log.warn("Received an invalid request", e);
|
||||
} catch (SearchServiceException e) {
|
||||
log.error("Error while searching with Discovery", e);
|
||||
}
|
||||
@@ -104,14 +108,14 @@ public class DiscoveryRestRepository extends AbstractDSpaceRestRepository {
|
||||
DSpaceObject scopeObject = scopeResolver.resolveScope(context, dsoScope);
|
||||
DiscoveryConfiguration configuration = searchConfigurationService.getDiscoveryConfigurationByNameOrDso(configurationName, scopeObject);
|
||||
|
||||
return discoverFacetConfigurationConverter.convert(configuration);
|
||||
return discoverFacetConfigurationConverter.convert(configurationName, dsoScope, configuration);
|
||||
}
|
||||
|
||||
public SearchSupportRest getSearchSupport() {
|
||||
return discoverSearchSupportConverter.convert();
|
||||
}
|
||||
|
||||
public FacetResultsRest getFacetObjects(String facetName, String query, String dsoType, String dsoScope, List<SearchFilter> searchFilters, Pageable page){
|
||||
public FacetResultsRest getFacetObjects(String facetName, String query, String dsoType, String dsoScope, List<SearchFilter> searchFilters, Pageable page) throws InvalidRequestException {
|
||||
|
||||
Context context = obtainContext();
|
||||
|
||||
@@ -124,9 +128,6 @@ public class DiscoveryRestRepository extends AbstractDSpaceRestRepository {
|
||||
discoverQuery = queryBuilder.buildFacetQuery(context, scopeObject, configuration, query, searchFilters, dsoType, page, facetName);
|
||||
searchResult = searchService.search(context, scopeObject, discoverQuery);
|
||||
|
||||
} catch (InvalidRequestException e) {
|
||||
log.warn("Received an invalid request", e);
|
||||
//TODO TOM handle invalid request
|
||||
} catch (SearchServiceException e) {
|
||||
log.error("Error while searching with Discovery", e);
|
||||
//TODO TOM handle search exception
|
||||
|
@@ -7,6 +7,12 @@
|
||||
*/
|
||||
package org.dspace.app.rest.repository;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.dspace.app.rest.converter.ItemConverter;
|
||||
import org.dspace.app.rest.model.ItemRest;
|
||||
import org.dspace.app.rest.model.hateoas.ItemResource;
|
||||
@@ -19,12 +25,6 @@ import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* This is the repository responsible to manage Item Rest object
|
||||
*
|
||||
|
@@ -7,6 +7,9 @@
|
||||
*/
|
||||
package org.dspace.app.rest.repository;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.app.rest.converter.MetadataFieldConverter;
|
||||
import org.dspace.app.rest.model.MetadataFieldRest;
|
||||
import org.dspace.app.rest.model.hateoas.MetadataFieldResource;
|
||||
@@ -18,9 +21,6 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is the repository responsible to manage MetadataField Rest object
|
||||
*
|
||||
|
@@ -7,6 +7,9 @@
|
||||
*/
|
||||
package org.dspace.app.rest.repository;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.app.rest.converter.MetadataSchemaConverter;
|
||||
import org.dspace.app.rest.model.MetadataSchemaRest;
|
||||
import org.dspace.app.rest.model.hateoas.MetadataSchemaResource;
|
||||
@@ -18,9 +21,6 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is the repository responsible to manage MetadataSchema Rest object
|
||||
*
|
||||
|
@@ -7,6 +7,11 @@
|
||||
*/
|
||||
package org.dspace.app.rest.repository;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.dspace.app.rest.converter.SiteConverter;
|
||||
import org.dspace.app.rest.model.SiteRest;
|
||||
import org.dspace.app.rest.model.hateoas.SiteResource;
|
||||
@@ -19,11 +24,6 @@ import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* This is the repository responsible to manage Item Rest object
|
||||
*
|
||||
|
@@ -7,6 +7,11 @@
|
||||
*/
|
||||
package org.dspace.app.rest.utils;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.core.Context;
|
||||
|
||||
|
@@ -7,6 +7,10 @@
|
||||
*/
|
||||
package org.dspace.app.rest.utils;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -20,17 +24,22 @@ import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.core.Constants;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.core.LogManager;
|
||||
import org.dspace.discovery.*;
|
||||
import org.dspace.discovery.configuration.*;
|
||||
import org.dspace.discovery.DiscoverFacetField;
|
||||
import org.dspace.discovery.DiscoverFilterQuery;
|
||||
import org.dspace.discovery.DiscoverQuery;
|
||||
import org.dspace.discovery.FacetYearRange;
|
||||
import org.dspace.discovery.SearchService;
|
||||
import org.dspace.discovery.SearchUtils;
|
||||
import org.dspace.discovery.configuration.DiscoveryConfiguration;
|
||||
import org.dspace.discovery.configuration.DiscoveryConfigurationParameters;
|
||||
import org.dspace.discovery.configuration.DiscoverySearchFilterFacet;
|
||||
import org.dspace.discovery.configuration.DiscoverySortConfiguration;
|
||||
import org.dspace.discovery.configuration.DiscoverySortFieldConfiguration;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class builds the queries for the /search and /facet endpoints.
|
||||
*/
|
||||
@@ -123,7 +132,8 @@ public class DiscoverQueryBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
private DiscoverQuery buildCommonDiscoverQuery(Context context, DiscoveryConfiguration discoveryConfiguration, String query, List<SearchFilter> searchFilters, String dsoType) throws InvalidSearchFilterException, InvalidDSpaceObjectTypeException {
|
||||
private DiscoverQuery buildCommonDiscoverQuery(Context context, DiscoveryConfiguration discoveryConfiguration, String query,
|
||||
List<SearchFilter> searchFilters, String dsoType) throws InvalidSearchFilterException, InvalidDSpaceObjectTypeException {
|
||||
DiscoverQuery queryArgs = buildBaseQueryForConfiguration(discoveryConfiguration);
|
||||
|
||||
//Add search filters
|
||||
@@ -231,7 +241,6 @@ public class DiscoverQueryBuilder {
|
||||
ArrayList<String> filterQueries = new ArrayList<>(searchFilters.size());
|
||||
|
||||
try {
|
||||
//TODO TOM take into account OR filters
|
||||
for (SearchFilter searchFilter : CollectionUtils.emptyIfNull(searchFilters)) {
|
||||
DiscoverFilterQuery filterQuery = searchService.toFilterQuery(context,
|
||||
searchFilter.getName(), searchFilter.getOperator(), searchFilter.getValue());
|
||||
|
@@ -7,20 +7,18 @@
|
||||
*/
|
||||
package org.dspace.app.rest.utils;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.service.CollectionService;
|
||||
import org.dspace.content.service.CommunityService;
|
||||
import org.dspace.core.Context;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Utility bean that can resolve a scope in the REST API to a DSpace Object
|
||||
*/
|
||||
|
@@ -8,7 +8,12 @@
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
|
||||
import org.dspace.app.rest.converter.DiscoverConfigurationConverter;
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.dspace.app.rest.model.SearchConfigurationRest;
|
||||
import org.dspace.discovery.configuration.DiscoveryConfiguration;
|
||||
import org.dspace.discovery.configuration.DiscoverySearchFilter;
|
||||
@@ -21,18 +26,6 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Set;
|
||||
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static junit.framework.TestCase.assertNull;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* This class' purpose is to test the DiscoverConfigurationConverter
|
||||
*/
|
||||
|
@@ -8,21 +8,20 @@
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.dspace.app.rest.model.FacetConfigurationRest;
|
||||
import org.dspace.discovery.configuration.*;
|
||||
import org.dspace.discovery.configuration.DiscoveryConfiguration;
|
||||
import org.dspace.discovery.configuration.DiscoverySearchFilterFacet;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* This class has the purpose to test the DiscoverFacetConfigurationConverter
|
||||
*/
|
||||
@@ -37,6 +36,8 @@ public class DiscoverFacetConfigurationConverterTest{
|
||||
@Mock
|
||||
private DiscoveryConfiguration discoveryConfiguration;
|
||||
|
||||
private String configurationName = "default";
|
||||
private String scopeObject = "ba9e1c83-8144-4e9c-9d58-bb97be573b46";
|
||||
|
||||
public void populateDiscoveryConfigurationWithEmptyList(){
|
||||
discoveryConfiguration.setSidebarFacets(new LinkedList<DiscoverySearchFilterFacet>());
|
||||
@@ -45,13 +46,13 @@ public class DiscoverFacetConfigurationConverterTest{
|
||||
@Test
|
||||
public void testReturnType() throws Exception{
|
||||
populateDiscoveryConfigurationWithEmptyList();
|
||||
facetConfigurationRest = discoverFacetConfigurationConverter.convert(discoveryConfiguration);
|
||||
facetConfigurationRest = discoverFacetConfigurationConverter.convert(configurationName, scopeObject, discoveryConfiguration);
|
||||
assertTrue(facetConfigurationRest.getSidebarFacets().isEmpty());
|
||||
assertEquals(FacetConfigurationRest.class, facetConfigurationRest.getClass());
|
||||
}
|
||||
@Test
|
||||
public void testConvertWithNullParamter() throws Exception{
|
||||
facetConfigurationRest = discoverFacetConfigurationConverter.convert(null);
|
||||
facetConfigurationRest = discoverFacetConfigurationConverter.convert(configurationName, scopeObject, null);
|
||||
assertNotNull(facetConfigurationRest);
|
||||
assertTrue(facetConfigurationRest.getSidebarFacets().isEmpty());
|
||||
}
|
||||
@@ -66,12 +67,12 @@ public class DiscoverFacetConfigurationConverterTest{
|
||||
|
||||
when(discoveryConfiguration.getSidebarFacets()).thenReturn(discoverySearchFilterFacets);
|
||||
|
||||
facetConfigurationRest = discoverFacetConfigurationConverter.convert(discoveryConfiguration);
|
||||
facetConfigurationRest = discoverFacetConfigurationConverter.convert(configurationName, scopeObject, discoveryConfiguration);
|
||||
|
||||
assertNotNull(facetConfigurationRest);
|
||||
assertTrue(!facetConfigurationRest.getSidebarFacets().isEmpty());
|
||||
assertEquals(discoverySearchFilterFacet.getIndexFieldName(), facetConfigurationRest.getSidebarFacets().get(0).getName());
|
||||
assertEquals(discoverySearchFilterFacet.getType(), facetConfigurationRest.getSidebarFacets().get(0).getType());
|
||||
assertEquals(discoverySearchFilterFacet.getType(), facetConfigurationRest.getSidebarFacets().get(0).getFacetType());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,7 +80,7 @@ public class DiscoverFacetConfigurationConverterTest{
|
||||
|
||||
when(discoveryConfiguration.getSidebarFacets()).thenReturn(new LinkedList<DiscoverySearchFilterFacet>());
|
||||
|
||||
facetConfigurationRest = discoverFacetConfigurationConverter.convert(discoveryConfiguration);
|
||||
facetConfigurationRest = discoverFacetConfigurationConverter.convert(configurationName, scopeObject, discoveryConfiguration);
|
||||
|
||||
assertNotNull(facetConfigurationRest);
|
||||
assertTrue(facetConfigurationRest.getSidebarFacets().isEmpty());
|
||||
@@ -90,7 +91,7 @@ public class DiscoverFacetConfigurationConverterTest{
|
||||
|
||||
when(discoveryConfiguration.getSidebarFacets()).thenReturn(null);
|
||||
|
||||
facetConfigurationRest = discoverFacetConfigurationConverter.convert(discoveryConfiguration);
|
||||
facetConfigurationRest = discoverFacetConfigurationConverter.convert(configurationName, scopeObject, discoveryConfiguration);
|
||||
|
||||
assertNotNull(facetConfigurationRest);
|
||||
assertTrue(facetConfigurationRest.getSidebarFacets().isEmpty());
|
||||
|
@@ -7,13 +7,13 @@
|
||||
*/
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.dspace.app.rest.model.SearchSupportRest;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* This class' purpose is to test the DiscoverSearchSupportConverter
|
||||
*/
|
||||
|
@@ -7,6 +7,10 @@
|
||||
*/
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.dspace.app.rest.model.RootRest;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
import org.junit.Before;
|
||||
@@ -16,10 +20,6 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* This class' purpose is to test the RootConvertor class.
|
||||
*/
|
||||
|
@@ -7,9 +7,10 @@
|
||||
*/
|
||||
package org.dspace.app.rest.link.search;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.dspace.app.rest.DiscoveryRestController;
|
||||
import org.dspace.app.rest.link.HalLinkFactory;
|
||||
import org.dspace.app.rest.link.search.FacetConfigurationResourceHalLinkFactory;
|
||||
import org.dspace.app.rest.model.hateoas.FacetConfigurationResource;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -17,8 +18,6 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.springframework.hateoas.mvc.ControllerLinkBuilder;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* This class' purpose is to test the FacetConfigurationResourceHalLinkFactory
|
||||
*/
|
||||
|
@@ -7,22 +7,16 @@
|
||||
*/
|
||||
package org.dspace.app.rest.link.search;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.dspace.app.rest.DiscoveryRestController;
|
||||
import org.dspace.app.rest.link.HalLinkFactory;
|
||||
import org.dspace.app.rest.model.SearchConfigurationRest;
|
||||
import org.dspace.app.rest.model.hateoas.SearchConfigurationResource;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.mvc.ControllerLinkBuilder;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* This class' purpose is to test the SearchConfigurationResourceHalLinkFactory
|
||||
|
@@ -7,14 +7,13 @@
|
||||
*/
|
||||
package org.dspace.app.rest.link.search;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.dspace.app.rest.DiscoveryRestController;
|
||||
import org.dspace.app.rest.model.hateoas.SearchConfigurationResource;
|
||||
import org.dspace.app.rest.model.hateoas.SearchResultsResource;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* This class' purpose is to test the SearchResultsResourceHalLinkFactory
|
||||
*/
|
||||
|
@@ -7,14 +7,13 @@
|
||||
*/
|
||||
package org.dspace.app.rest.link.search;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.dspace.app.rest.DiscoveryRestController;
|
||||
import org.dspace.app.rest.model.hateoas.SearchConfigurationResource;
|
||||
import org.dspace.app.rest.model.hateoas.SearchSupportResource;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* This class' purpose is to test the SearchSupportHalLinkFactory class
|
||||
*/
|
||||
|
@@ -7,12 +7,12 @@
|
||||
*/
|
||||
package org.dspace.app.rest.model;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FacetConfigurationRestTest {
|
||||
|
||||
FacetConfigurationRest facetConfigurationRest;
|
||||
@@ -29,9 +29,8 @@ public class FacetConfigurationRestTest {
|
||||
|
||||
@Test
|
||||
public void testAddSidebarFacetsContainsCorrectSidebarFacet(){
|
||||
FacetConfigurationRest.SidebarFacet sidebarFacet = new FacetConfigurationRest.SidebarFacet();
|
||||
sidebarFacet.setType("date");
|
||||
sidebarFacet.setName("dateName");
|
||||
SearchFacetEntryRest sidebarFacet = new SearchFacetEntryRest("dateName");
|
||||
sidebarFacet.setFacetType("date");
|
||||
|
||||
facetConfigurationRest.addSidebarFacet(sidebarFacet);
|
||||
|
||||
|
@@ -7,12 +7,12 @@
|
||||
*/
|
||||
package org.dspace.app.rest.model;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* This class' purpose is to test the FacetResultsRest class
|
||||
*/
|
||||
|
@@ -7,15 +7,11 @@
|
||||
*/
|
||||
package org.dspace.app.rest.model;
|
||||
|
||||
import org.dspace.app.rest.DiscoveryRestController;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* This class' purpose is to test the SearchConfigurationRest
|
||||
*/
|
||||
|
@@ -7,13 +7,13 @@
|
||||
*/
|
||||
package org.dspace.app.rest.model;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.dspace.app.rest.DiscoveryRestController;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* This class' purpose is to test the SearchSupportRest class
|
||||
*/
|
||||
|
@@ -7,13 +7,12 @@
|
||||
*/
|
||||
package org.dspace.app.rest.model.hateoas;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.dspace.app.rest.model.FacetConfigurationRest;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
/**
|
||||
* This class' purpose is to test the FacetConfigurationRest class
|
||||
*/
|
||||
|
@@ -7,7 +7,8 @@
|
||||
*/
|
||||
package org.dspace.app.rest.model.hateoas;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.dspace.app.rest.model.RootRest;
|
||||
import org.junit.Before;
|
||||
|
@@ -7,14 +7,13 @@
|
||||
*/
|
||||
package org.dspace.app.rest.model.hateoas;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.dspace.app.rest.model.SearchConfigurationRest;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* This class' purpose is to test the SearchConfigurationResource
|
||||
*/
|
||||
|
@@ -7,14 +7,13 @@
|
||||
*/
|
||||
package org.dspace.app.rest.model.hateoas;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.dspace.app.rest.model.SearchSupportRest;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* This class' purpose is to test the SearchSupportResource class
|
||||
*/
|
||||
|
Reference in New Issue
Block a user