mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Merge pull request #2547 from atmire/DS-3533_Projections
DS-3533 projections support
This commit is contained in:
@@ -11,6 +11,7 @@ import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.dspace.app.rest.converter.ConverterService;
|
||||
import org.dspace.app.rest.converter.EPersonConverter;
|
||||
import org.dspace.app.rest.link.HalLinkService;
|
||||
import org.dspace.app.rest.model.AuthenticationStatusRest;
|
||||
@@ -18,6 +19,7 @@ import org.dspace.app.rest.model.AuthnRest;
|
||||
import org.dspace.app.rest.model.EPersonRest;
|
||||
import org.dspace.app.rest.model.hateoas.AuthenticationStatusResource;
|
||||
import org.dspace.app.rest.model.hateoas.AuthnResource;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.app.rest.utils.ContextUtil;
|
||||
import org.dspace.app.rest.utils.Utils;
|
||||
import org.dspace.core.Context;
|
||||
@@ -49,6 +51,9 @@ public class AuthenticationRestController implements InitializingBean {
|
||||
@Autowired
|
||||
DiscoverableEndpointsService discoverableEndpointsService;
|
||||
|
||||
@Autowired
|
||||
private ConverterService converter;
|
||||
|
||||
@Autowired
|
||||
private EPersonConverter ePersonConverter;
|
||||
|
||||
@@ -65,24 +70,24 @@ public class AuthenticationRestController implements InitializingBean {
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
public AuthnResource authn() throws SQLException {
|
||||
AuthnResource authnResource = new AuthnResource(new AuthnRest(), utils);
|
||||
halLinkService.addLinks(authnResource);
|
||||
return authnResource;
|
||||
public AuthnResource authn() {
|
||||
AuthnRest authnRest = new AuthnRest();
|
||||
authnRest.setProjection(utils.obtainProjection());
|
||||
return converter.toResource(authnRest);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/status", method = RequestMethod.GET)
|
||||
public AuthenticationStatusResource status(HttpServletRequest request) throws SQLException {
|
||||
Context context = ContextUtil.obtainContext(request);
|
||||
EPersonRest ePersonRest = null;
|
||||
Projection projection = utils.obtainProjection();
|
||||
if (context.getCurrentUser() != null) {
|
||||
ePersonRest = ePersonConverter.fromModelWithGroups(context, context.getCurrentUser());
|
||||
ePersonRest = ePersonConverter.fromModelWithGroups(context, context.getCurrentUser(), projection);
|
||||
}
|
||||
|
||||
AuthenticationStatusResource authenticationStatusResource = new AuthenticationStatusResource(
|
||||
new AuthenticationStatusRest(ePersonRest), utils);
|
||||
|
||||
halLinkService.addLinks(authenticationStatusResource);
|
||||
AuthenticationStatusRest authenticationStatusRest = new AuthenticationStatusRest(ePersonRest);
|
||||
authenticationStatusRest.setProjection(projection);
|
||||
AuthenticationStatusResource authenticationStatusResource = converter.toResource(authenticationStatusRest);
|
||||
|
||||
return authenticationStatusResource;
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ import java.util.UUID;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.dspace.app.rest.converter.DSpaceObjectConverter;
|
||||
import org.dspace.app.rest.converter.ConverterService;
|
||||
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||
import org.dspace.app.rest.link.HalLinkService;
|
||||
import org.dspace.app.rest.model.BitstreamRest;
|
||||
@@ -63,7 +63,7 @@ public class BitstreamBundleController {
|
||||
private BitstreamService bitstreamService;
|
||||
|
||||
@Autowired
|
||||
DSpaceObjectConverter<Bundle, BundleRest> dsoConverter;
|
||||
ConverterService converter;
|
||||
|
||||
@Autowired
|
||||
HalLinkService halLinkService;
|
||||
@@ -106,8 +106,8 @@ public class BitstreamBundleController {
|
||||
return ControllerUtils.toEmptyResponse(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
BundleResource bundleResource = new BundleResource(dsoConverter.fromModel(bundles.get(0)), utils);
|
||||
halLinkService.addLinks(bundleResource);
|
||||
BundleResource bundleResource = converter.toResource(
|
||||
converter.toRest(bundles.get(0), utils.obtainProjection()));
|
||||
|
||||
return ControllerUtils.toResponseEntity(HttpStatus.OK, null, bundleResource);
|
||||
}
|
||||
@@ -126,7 +126,7 @@ public class BitstreamBundleController {
|
||||
@RequestMapping(method = RequestMethod.PUT, consumes = {"text/uri-list"})
|
||||
@PreAuthorize("hasPermission(#uuid, 'BITSTREAM','WRITE')")
|
||||
@PostAuthorize("returnObject != null")
|
||||
public BundleResource move(@PathVariable UUID uuid, HttpServletResponse response,
|
||||
public BundleRest move(@PathVariable UUID uuid, HttpServletResponse response,
|
||||
HttpServletRequest request)
|
||||
throws SQLException, IOException, AuthorizeException {
|
||||
Context context = ContextUtil.obtainContext(request);
|
||||
@@ -143,17 +143,11 @@ public class BitstreamBundleController {
|
||||
throw new ResourceNotFoundException("Bitstream with id: " + uuid + " not found");
|
||||
}
|
||||
|
||||
Bundle targetBundle = bitstreamRestRepository.performBitstreamMove(context, bitstream, (Bundle) dsoList.get(0));
|
||||
|
||||
if (targetBundle == null) {
|
||||
return null;
|
||||
}
|
||||
BundleResource bundleResource = new BundleResource(dsoConverter.fromModel(targetBundle), utils);
|
||||
halLinkService.addLinks(bundleResource);
|
||||
BundleRest bundleRest = bitstreamRestRepository.performBitstreamMove(context, bitstream,
|
||||
(Bundle) dsoList.get(0));
|
||||
|
||||
context.commit();
|
||||
|
||||
return bundleResource;
|
||||
|
||||
return bundleRest;
|
||||
}
|
||||
}
|
||||
|
@@ -23,21 +23,17 @@ import javax.ws.rs.core.Response;
|
||||
import org.apache.catalina.connector.ClientAbortException;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.app.rest.converter.BitstreamConverter;
|
||||
import org.dspace.app.rest.converter.DSpaceObjectConverter;
|
||||
import org.dspace.app.rest.converter.ConverterService;
|
||||
import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
||||
import org.dspace.app.rest.link.HalLinkService;
|
||||
import org.dspace.app.rest.model.BitstreamRest;
|
||||
import org.dspace.app.rest.model.BundleRest;
|
||||
import org.dspace.app.rest.model.hateoas.BitstreamResource;
|
||||
import org.dspace.app.rest.repository.BitstreamRestRepository;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.app.rest.utils.ContextUtil;
|
||||
import org.dspace.app.rest.utils.MultipartFileSender;
|
||||
import org.dspace.app.rest.utils.Utils;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Bitstream;
|
||||
import org.dspace.content.BitstreamFormat;
|
||||
import org.dspace.content.Bundle;
|
||||
import org.dspace.content.service.BitstreamFormatService;
|
||||
import org.dspace.content.service.BitstreamService;
|
||||
import org.dspace.core.Context;
|
||||
@@ -86,12 +82,6 @@ public class BitstreamRestController {
|
||||
@Autowired
|
||||
BitstreamFormatService bitstreamFormatService;
|
||||
|
||||
@Autowired
|
||||
BitstreamRestRepository bitstreamRestRepository;
|
||||
|
||||
@Autowired
|
||||
DSpaceObjectConverter<Bundle, BundleRest> dsoConverter;
|
||||
|
||||
@Autowired
|
||||
private EventService eventService;
|
||||
|
||||
@@ -102,14 +92,11 @@ public class BitstreamRestController {
|
||||
private ConfigurationService configurationService;
|
||||
|
||||
@Autowired
|
||||
BitstreamConverter converter;
|
||||
ConverterService converter;
|
||||
|
||||
@Autowired
|
||||
Utils utils;
|
||||
|
||||
@Autowired
|
||||
HalLinkService halLinkService;
|
||||
|
||||
@PreAuthorize("hasPermission(#uuid, 'BITSTREAM', 'READ')")
|
||||
@RequestMapping( method = {RequestMethod.GET, RequestMethod.HEAD}, value = "content")
|
||||
public void retrieve(@PathVariable UUID uuid, HttpServletResponse response,
|
||||
@@ -253,7 +240,7 @@ public class BitstreamRestController {
|
||||
|
||||
context.commit();
|
||||
|
||||
return (BitstreamResource) utils.getResourceRepository(BitstreamRest.CATEGORY, BitstreamRest.NAME)
|
||||
.wrapResource(converter.fromModel(context.reloadEntity(bitstream)));
|
||||
BitstreamRest bitstreamRest = converter.toRest(context.reloadEntity(bitstream), Projection.DEFAULT);
|
||||
return converter.toResource(bitstreamRest);
|
||||
}
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.app.rest.converter.BitstreamConverter;
|
||||
import org.dspace.app.rest.converter.ConverterService;
|
||||
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||
import org.dspace.app.rest.model.BitstreamRest;
|
||||
import org.dspace.app.rest.model.BundleRest;
|
||||
@@ -25,7 +25,6 @@ import org.dspace.app.rest.model.hateoas.BitstreamResource;
|
||||
import org.dspace.app.rest.repository.BundleRestRepository;
|
||||
import org.dspace.app.rest.utils.ContextUtil;
|
||||
import org.dspace.app.rest.utils.Utils;
|
||||
import org.dspace.content.Bitstream;
|
||||
import org.dspace.content.Bundle;
|
||||
import org.dspace.content.service.BundleService;
|
||||
import org.dspace.core.Context;
|
||||
@@ -72,10 +71,10 @@ public class BundleUploadBitstreamController {
|
||||
private BundleService bundleService;
|
||||
|
||||
@Autowired
|
||||
private BitstreamConverter bitstreamConverter;
|
||||
private BundleRestRepository bundleRestRepository;
|
||||
|
||||
@Autowired
|
||||
private BundleRestRepository bundleRestRepository;
|
||||
private ConverterService converter;
|
||||
|
||||
/**
|
||||
* Method to upload a Bitstream to a Bundle with the given UUID in the URL. This will create a Bitstream with the
|
||||
@@ -92,7 +91,6 @@ public class BundleUploadBitstreamController {
|
||||
|
||||
Context context = ContextUtil.obtainContext(request);
|
||||
Bundle bundle = null;
|
||||
Bitstream bitstream = null;
|
||||
try {
|
||||
bundle = bundleService.find(context, uuid);
|
||||
} catch (SQLException e) {
|
||||
@@ -110,10 +108,10 @@ public class BundleUploadBitstreamController {
|
||||
throw new UnprocessableEntityException("The InputStream from the file couldn't be read", e);
|
||||
}
|
||||
|
||||
bitstream = bundleRestRepository.uploadBitstream(context, bundle, uploadfile.getOriginalFilename(),
|
||||
fileInputStream, properties);
|
||||
BitstreamRest bitstreamRest = bundleRestRepository.uploadBitstream(
|
||||
context, bundle, uploadfile.getOriginalFilename(), fileInputStream, properties);
|
||||
BitstreamResource bitstreamResource = converter.toResource(bitstreamRest);
|
||||
|
||||
BitstreamResource bitstreamResource = new BitstreamResource(bitstreamConverter.fromModel(bitstream), utils);
|
||||
return ControllerUtils.toResponseEntity(HttpStatus.CREATED, null, bitstreamResource);
|
||||
}
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@ import java.util.UUID;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.dspace.app.rest.converter.ConverterService;
|
||||
import org.dspace.app.rest.converter.HarvestedCollectionConverter;
|
||||
import org.dspace.app.rest.link.HalLinkService;
|
||||
import org.dspace.app.rest.model.HarvestedCollectionRest;
|
||||
@@ -48,6 +49,9 @@ public class CollectionHarvestSettingsController {
|
||||
@Autowired
|
||||
CollectionService collectionService;
|
||||
|
||||
@Autowired
|
||||
ConverterService converter;
|
||||
|
||||
@Autowired
|
||||
HarvestedCollectionService harvestedCollectionService;
|
||||
|
||||
@@ -80,9 +84,7 @@ public class CollectionHarvestSettingsController {
|
||||
}
|
||||
|
||||
HarvestedCollectionRest harvestedCollectionRest = harvestedCollectionRestRepository.findOne(collection);
|
||||
HarvestedCollectionResource resource = new HarvestedCollectionResource(harvestedCollectionRest);
|
||||
|
||||
halLinkService.addLinks(resource);
|
||||
HarvestedCollectionResource resource = converter.toResource(harvestedCollectionRest);
|
||||
|
||||
return resource;
|
||||
}
|
||||
@@ -114,8 +116,7 @@ public class CollectionHarvestSettingsController {
|
||||
|
||||
// Return a harvestedCollectionResource only if a new harvestedCollection was created
|
||||
if (harvestedCollectionRest != null) {
|
||||
harvestedCollectionResource = new HarvestedCollectionResource(harvestedCollectionRest);
|
||||
halLinkService.addLinks(harvestedCollectionResource);
|
||||
harvestedCollectionResource = converter.toResource(harvestedCollectionRest);
|
||||
}
|
||||
|
||||
context.commit();
|
||||
|
@@ -14,6 +14,7 @@ import java.util.Objects;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.app.rest.converter.ConverterService;
|
||||
import org.dspace.app.rest.link.HalLinkService;
|
||||
import org.dspace.app.rest.model.FacetConfigurationRest;
|
||||
import org.dspace.app.rest.model.FacetResultsRest;
|
||||
@@ -61,6 +62,9 @@ public class DiscoveryRestController implements InitializingBean {
|
||||
@Autowired
|
||||
private HalLinkService halLinkService;
|
||||
|
||||
@Autowired
|
||||
private ConverterService converter;
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
discoverableEndpointsService
|
||||
@@ -74,8 +78,7 @@ public class DiscoveryRestController implements InitializingBean {
|
||||
throws Exception {
|
||||
|
||||
SearchSupportRest searchSupportRest = discoveryRestRepository.getSearchSupport();
|
||||
SearchSupportResource searchSupportResource = new SearchSupportResource(searchSupportRest);
|
||||
halLinkService.addLinks(searchSupportResource);
|
||||
SearchSupportResource searchSupportResource = converter.toResource(searchSupportRest);
|
||||
return searchSupportResource;
|
||||
}
|
||||
|
||||
@@ -91,9 +94,7 @@ public class DiscoveryRestController implements InitializingBean {
|
||||
SearchConfigurationRest searchConfigurationRest = discoveryRestRepository
|
||||
.getSearchConfiguration(dsoScope, configuration);
|
||||
|
||||
SearchConfigurationResource searchConfigurationResource = new SearchConfigurationResource(
|
||||
searchConfigurationRest);
|
||||
halLinkService.addLinks(searchConfigurationResource);
|
||||
SearchConfigurationResource searchConfigurationResource = converter.toResource(searchConfigurationRest);
|
||||
return searchConfigurationResource;
|
||||
}
|
||||
|
||||
@@ -142,9 +143,8 @@ public class DiscoveryRestController implements InitializingBean {
|
||||
}
|
||||
|
||||
//Get the Search results in JSON format
|
||||
SearchResultsRest searchResultsRest = null;
|
||||
searchResultsRest = discoveryRestRepository
|
||||
.getSearchObjects(query, dsoType, dsoScope, configuration, searchFilters, page);
|
||||
SearchResultsRest searchResultsRest = discoveryRestRepository
|
||||
.getSearchObjects(query, dsoType, dsoScope, configuration, searchFilters, page, utils.obtainProjection());
|
||||
|
||||
//Convert the Search JSON results to paginated HAL resources
|
||||
SearchResultsResource searchResultsResource = new SearchResultsResource(searchResultsRest, utils, page);
|
||||
@@ -164,7 +164,7 @@ public class DiscoveryRestController implements InitializingBean {
|
||||
|
||||
FacetConfigurationRest facetConfigurationRest = discoveryRestRepository
|
||||
.getFacetsConfiguration(dsoScope, configuration);
|
||||
FacetConfigurationResource facetConfigurationResource = new FacetConfigurationResource(facetConfigurationRest);
|
||||
FacetConfigurationResource facetConfigurationResource = converter.toResource(facetConfigurationRest);
|
||||
|
||||
halLinkService.addLinks(facetConfigurationResource, pageable);
|
||||
return facetConfigurationResource;
|
||||
@@ -192,7 +192,7 @@ public class DiscoveryRestController implements InitializingBean {
|
||||
FacetResultsRest facetResultsRest = discoveryRestRepository
|
||||
.getFacetObjects(facetName, prefix, query, dsoType, dsoScope, configuration, searchFilters, page);
|
||||
|
||||
FacetResultsResource facetResultsResource = new FacetResultsResource(facetResultsRest);
|
||||
FacetResultsResource facetResultsResource = converter.toResource(facetResultsRest);
|
||||
|
||||
halLinkService.addLinks(facetResultsResource, page);
|
||||
return facetResultsResource;
|
||||
|
@@ -12,12 +12,12 @@ import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.dspace.app.rest.converter.ConverterService;
|
||||
import org.dspace.app.rest.link.HalLinkService;
|
||||
import org.dspace.app.rest.model.HarvesterMetadataRest;
|
||||
import org.dspace.app.rest.model.hateoas.HarvesterMetadataResource;
|
||||
import org.dspace.app.rest.utils.Utils;
|
||||
import org.dspace.harvest.OAIHarvester;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
@@ -38,6 +38,9 @@ public class HarvesterMetadataController {
|
||||
@Autowired
|
||||
private HalLinkService halLinkService;
|
||||
|
||||
@Autowired
|
||||
private ConverterService converter;
|
||||
|
||||
/**
|
||||
* GET endpoint that returns all available metadata formats
|
||||
* @param request The request object
|
||||
@@ -46,15 +49,14 @@ public class HarvesterMetadataController {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
public HarvesterMetadataResource get(HttpServletRequest request,
|
||||
HttpServletResponse response) {
|
||||
HttpServletResponse response) {
|
||||
List<Map<String,String>> configs = OAIHarvester.getAvailableMetadataFormats();
|
||||
|
||||
HarvesterMetadataRest data = new HarvesterMetadataRest();
|
||||
data.setProjection(utils.obtainProjection());
|
||||
data.setConfigs(configs);
|
||||
|
||||
HarvesterMetadataResource resource = new HarvesterMetadataResource(data, utils);
|
||||
halLinkService.addLinks(resource);
|
||||
|
||||
HarvesterMetadataResource resource = converter.toResource(data);
|
||||
return resource;
|
||||
}
|
||||
|
||||
|
@@ -13,15 +13,15 @@ import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.atteo.evo.inflector.English;
|
||||
import org.dspace.app.rest.converter.GenericDSpaceObjectConverter;
|
||||
import org.dspace.app.rest.converter.ConverterService;
|
||||
import org.dspace.app.rest.model.DSpaceObjectRest;
|
||||
import org.dspace.app.rest.utils.ContextUtil;
|
||||
import org.dspace.app.rest.utils.Utils;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.identifier.IdentifierNotFoundException;
|
||||
@@ -53,7 +53,10 @@ public class IdentifierRestController implements InitializingBean {
|
||||
Logger.getLogger(IdentifierRestController.class);
|
||||
|
||||
@Autowired
|
||||
private GenericDSpaceObjectConverter converter;
|
||||
private ConverterService converter;
|
||||
|
||||
@Autowired
|
||||
private Utils utils;
|
||||
|
||||
@Autowired
|
||||
private DiscoverableEndpointsService discoverableEndpointsService;
|
||||
@@ -84,7 +87,7 @@ public class IdentifierRestController implements InitializingBean {
|
||||
try {
|
||||
dso = identifierService.resolve(context, id);
|
||||
if (dso != null) {
|
||||
DSpaceObjectRest dsor = converter.convert(dso);
|
||||
DSpaceObjectRest dsor = converter.toRest(dso, utils.obtainProjection());
|
||||
URI link = linkTo(dsor.getController(), dsor.getCategory(),
|
||||
English.plural(dsor.getType()))
|
||||
.slash(dsor.getId()).toUri();
|
||||
|
@@ -16,12 +16,13 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.dspace.app.rest.converter.BundleConverter;
|
||||
import org.dspace.app.rest.converter.ConverterService;
|
||||
import org.dspace.app.rest.converter.MetadataConverter;
|
||||
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||
import org.dspace.app.rest.model.BundleRest;
|
||||
import org.dspace.app.rest.model.ItemRest;
|
||||
import org.dspace.app.rest.model.hateoas.BundleResource;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.app.rest.repository.ItemRestRepository;
|
||||
import org.dspace.app.rest.utils.ContextUtil;
|
||||
import org.dspace.app.rest.utils.Utils;
|
||||
@@ -63,19 +64,18 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
+ "/" + BundleRest.PLURAL_NAME)
|
||||
public class ItemAddBundleController {
|
||||
|
||||
@Autowired
|
||||
ConverterService converter;
|
||||
|
||||
@Autowired
|
||||
ItemService itemService;
|
||||
|
||||
@Autowired
|
||||
ItemRestRepository itemRestRepository;
|
||||
|
||||
@Autowired
|
||||
BundleConverter converter;
|
||||
|
||||
@Autowired
|
||||
MetadataConverter metadataConverter;
|
||||
|
||||
|
||||
@Autowired
|
||||
Utils utils;
|
||||
|
||||
@@ -107,10 +107,8 @@ public class ItemAddBundleController {
|
||||
}
|
||||
|
||||
Bundle bundle = itemRestRepository.addBundleToItem(context, item, bundleRest);
|
||||
|
||||
BundleResource bundleResource = new BundleResource(converter.convert(bundle), utils);
|
||||
BundleResource bundleResource = converter.toResource(converter.toRest(bundle, Projection.DEFAULT));
|
||||
return ControllerUtils.toResponseEntity(HttpStatus.CREATED, null, bundleResource);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -17,10 +17,11 @@ import java.util.UUID;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.dspace.app.rest.converter.CollectionConverter;
|
||||
import org.dspace.app.rest.converter.ConverterService;
|
||||
import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
||||
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||
import org.dspace.app.rest.model.CollectionRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.app.rest.utils.ContextUtil;
|
||||
import org.dspace.app.rest.utils.Utils;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
@@ -59,7 +60,7 @@ public class ItemOwningCollectionUpdateRestController {
|
||||
AuthorizeService authorizeService;
|
||||
|
||||
@Autowired
|
||||
CollectionConverter converter;
|
||||
ConverterService converter;
|
||||
|
||||
@Autowired
|
||||
Utils utils;
|
||||
@@ -96,7 +97,7 @@ public class ItemOwningCollectionUpdateRestController {
|
||||
if (targetCollection == null) {
|
||||
return null;
|
||||
}
|
||||
return converter.fromModel(targetCollection);
|
||||
return converter.toRest(targetCollection, Projection.DEFAULT);
|
||||
|
||||
}
|
||||
|
||||
|
@@ -19,7 +19,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.rest.converter.CollectionConverter;
|
||||
import org.dspace.app.rest.converter.ConverterService;
|
||||
import org.dspace.app.rest.exception.MethodNotAllowedException;
|
||||
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||
import org.dspace.app.rest.link.HalLinkService;
|
||||
@@ -56,7 +56,7 @@ public class MappedCollectionRestController {
|
||||
private ItemService itemService;
|
||||
|
||||
@Autowired
|
||||
private CollectionConverter collectionConverter;
|
||||
private ConverterService converter;
|
||||
|
||||
@Autowired
|
||||
private CollectionService collectionService;
|
||||
@@ -99,18 +99,16 @@ public class MappedCollectionRestController {
|
||||
List<CollectionRest> mappingCollectionRest = new LinkedList<>();
|
||||
for (Collection collection : collections) {
|
||||
if (collection.getID() != owningCollectionUuid) {
|
||||
mappingCollectionRest.add(collectionConverter.fromModel(collection));
|
||||
mappingCollectionRest.add(converter.toRest(collection, utils.obtainProjection()));
|
||||
}
|
||||
}
|
||||
|
||||
MappedCollectionRestWrapper mappingCollectionRestWrapper = new MappedCollectionRestWrapper();
|
||||
mappingCollectionRestWrapper.setProjection(utils.obtainProjection());
|
||||
mappingCollectionRestWrapper.setMappedCollectionRestList(mappingCollectionRest);
|
||||
mappingCollectionRestWrapper.setItem(item);
|
||||
MappedCollectionResourceWrapper mappingCollectionResourceWrapper = new MappedCollectionResourceWrapper(
|
||||
mappingCollectionRestWrapper, utils, pageable);
|
||||
|
||||
|
||||
halLinkService.addLinks(mappingCollectionResourceWrapper);
|
||||
MappedCollectionResourceWrapper mappingCollectionResourceWrapper =
|
||||
converter.toResource(mappingCollectionRestWrapper);
|
||||
|
||||
return mappingCollectionResourceWrapper;
|
||||
|
||||
|
@@ -17,7 +17,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.rest.converter.ItemConverter;
|
||||
import org.dspace.app.rest.converter.ConverterService;
|
||||
import org.dspace.app.rest.link.HalLinkService;
|
||||
import org.dspace.app.rest.model.ItemRest;
|
||||
import org.dspace.app.rest.model.MappedItemRestWrapper;
|
||||
@@ -54,7 +54,7 @@ public class MappedItemRestController {
|
||||
private ItemService itemService;
|
||||
|
||||
@Autowired
|
||||
private ItemConverter itemConverter;
|
||||
private ConverterService converter;
|
||||
|
||||
@Autowired
|
||||
Utils utils;
|
||||
@@ -96,11 +96,12 @@ public class MappedItemRestController {
|
||||
while (itemIterator.hasNext()) {
|
||||
Item item = itemIterator.next();
|
||||
if (item.getOwningCollection().getID() != uuid) {
|
||||
mappedItemRestList.add(itemConverter.fromModel(item));
|
||||
mappedItemRestList.add(converter.toRest(item, utils.obtainProjection()));
|
||||
}
|
||||
}
|
||||
|
||||
MappedItemRestWrapper mappedItemRestWrapper = new MappedItemRestWrapper();
|
||||
mappedItemRestWrapper.setProjection(utils.obtainProjection());
|
||||
mappedItemRestWrapper.setMappedItemRestList(mappedItemRestList);
|
||||
mappedItemRestWrapper.setCollectionUuid(uuid);
|
||||
MappedItemResourceWrapper mappedItemResourceWrapper =
|
||||
|
@@ -13,11 +13,12 @@ import java.util.List;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.dspace.app.rest.converter.RelationshipTypeConverter;
|
||||
import org.dspace.app.rest.converter.ConverterService;
|
||||
import org.dspace.app.rest.link.HalLinkService;
|
||||
import org.dspace.app.rest.model.RelationshipTypeRest;
|
||||
import org.dspace.app.rest.model.RelationshipTypeRestWrapper;
|
||||
import org.dspace.app.rest.model.hateoas.RelationshipTypeResourceWrapper;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.app.rest.utils.ContextUtil;
|
||||
import org.dspace.app.rest.utils.Utils;
|
||||
import org.dspace.content.EntityType;
|
||||
@@ -48,7 +49,7 @@ public class RelationshipTypeRestController {
|
||||
private EntityTypeService entityTypeService;
|
||||
|
||||
@Autowired
|
||||
private RelationshipTypeConverter relationshipTypeConverter;
|
||||
private ConverterService converter;
|
||||
|
||||
@Autowired
|
||||
private Utils utils;
|
||||
@@ -67,7 +68,8 @@ public class RelationshipTypeRestController {
|
||||
* @throws SQLException If something goes wrong
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
public RelationshipTypeResourceWrapper retrieve(@PathVariable Integer id, HttpServletResponse response,
|
||||
public RelationshipTypeResourceWrapper retrieve(@PathVariable Integer id,
|
||||
HttpServletResponse response,
|
||||
HttpServletRequest request) throws SQLException {
|
||||
Context context = ContextUtil.obtainContext(request);
|
||||
EntityType entityType = entityTypeService.find(context, id);
|
||||
@@ -75,19 +77,19 @@ public class RelationshipTypeRestController {
|
||||
|
||||
List<RelationshipTypeRest> relationshipTypeRests = new LinkedList<>();
|
||||
|
||||
Projection projection = utils.obtainProjection();
|
||||
for (RelationshipType relationshipType : list) {
|
||||
relationshipTypeRests.add(relationshipTypeConverter.fromModel(relationshipType));
|
||||
relationshipTypeRests.add(converter.toRest(relationshipType, projection));
|
||||
}
|
||||
|
||||
|
||||
RelationshipTypeRestWrapper relationshipTypeRestWrapper = new RelationshipTypeRestWrapper();
|
||||
relationshipTypeRestWrapper.setProjection(projection);
|
||||
relationshipTypeRestWrapper.setEntityTypeId(id);
|
||||
relationshipTypeRestWrapper.setEntityTypeLabel(entityType.getLabel());
|
||||
relationshipTypeRestWrapper.setRelationshipTypeRestList(relationshipTypeRests);
|
||||
|
||||
RelationshipTypeResourceWrapper relationshipTypeResourceWrapper = new RelationshipTypeResourceWrapper(
|
||||
relationshipTypeRestWrapper, utils);
|
||||
halLinkService.addLinks(relationshipTypeResourceWrapper);
|
||||
RelationshipTypeResourceWrapper relationshipTypeResourceWrapper =
|
||||
converter.toResource(relationshipTypeRestWrapper);
|
||||
return relationshipTypeResourceWrapper;
|
||||
}
|
||||
}
|
||||
|
@@ -22,17 +22,16 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.atteo.evo.inflector.English;
|
||||
import org.dspace.app.rest.converter.ConverterService;
|
||||
import org.dspace.app.rest.converter.JsonPatchConverter;
|
||||
import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
||||
import org.dspace.app.rest.exception.PaginationException;
|
||||
@@ -67,7 +66,6 @@ import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
||||
import org.springframework.data.web.PagedResourcesAssembler;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.PagedResources;
|
||||
import org.springframework.hateoas.Resource;
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
import org.springframework.hateoas.Resources;
|
||||
import org.springframework.hateoas.UriTemplate;
|
||||
@@ -115,6 +113,9 @@ public class RestResourceController implements InitializingBean {
|
||||
@Autowired
|
||||
HalLinkService linkService;
|
||||
|
||||
@Autowired
|
||||
ConverterService converter;
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
List<Link> links = new ArrayList<Link>();
|
||||
@@ -137,22 +138,20 @@ public class RestResourceController implements InitializingBean {
|
||||
*
|
||||
* Note that the regular expression in the request mapping accept a number as identifier;
|
||||
*
|
||||
* Please see {@link RestResourceController#findOne(String, String, String, String)} for findOne with string as
|
||||
* Please see {@link RestResourceController#findOne(String, String, String)} for findOne with string as
|
||||
* identifier
|
||||
* and see {@link RestResourceController#findOne(String, String, UUID, String)} for uuid as identifier
|
||||
* and see {@link RestResourceController#findOne(String, String, UUID)} for uuid as identifier
|
||||
*
|
||||
* @param apiCategory
|
||||
* @param model
|
||||
* @param id
|
||||
* @param projection
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = REGEX_REQUESTMAPPING_IDENTIFIER_AS_DIGIT)
|
||||
@SuppressWarnings("unchecked")
|
||||
public DSpaceResource<RestAddressableModel> findOne(@PathVariable String apiCategory, @PathVariable String model,
|
||||
@PathVariable Integer id,
|
||||
@RequestParam(required = false) String projection) {
|
||||
return findOneInternal(apiCategory, model, id, projection);
|
||||
@PathVariable Integer id) {
|
||||
return findOneInternal(apiCategory, model, id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,22 +170,20 @@ public class RestResourceController implements InitializingBean {
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* Please see {@link RestResourceController#findOne(String, String, Integer, String)} for findOne with number as
|
||||
* Please see {@link RestResourceController#findOne(String, String, Integer)} for findOne with number as
|
||||
* identifier
|
||||
* and see {@link RestResourceController#findOne(String, String, UUID, String)} for uuid as identifier
|
||||
* and see {@link RestResourceController#findOne(String, String, UUID)} for uuid as identifier
|
||||
*
|
||||
* @param apiCategory
|
||||
* @param model
|
||||
* @param id
|
||||
* @param projection
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = REGEX_REQUESTMAPPING_IDENTIFIER_AS_STRING_VERSION_STRONG)
|
||||
@SuppressWarnings("unchecked")
|
||||
public DSpaceResource<RestAddressableModel> findOne(@PathVariable String apiCategory, @PathVariable String model,
|
||||
@PathVariable String id,
|
||||
@RequestParam(required = false) String projection) {
|
||||
return findOneInternal(apiCategory, model, id, projection);
|
||||
@PathVariable String id) {
|
||||
return findOneInternal(apiCategory, model, id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,22 +191,20 @@ public class RestResourceController implements InitializingBean {
|
||||
*
|
||||
* Note that the regular expression in the request mapping accept a UUID as identifier;
|
||||
*
|
||||
* Please see {@link RestResourceController#findOne(String, String, Integer, String)} for findOne with number as
|
||||
* Please see {@link RestResourceController#findOne(String, String, Integer)} for findOne with number as
|
||||
* identifier
|
||||
* and see {@link RestResourceController#findOne(String, String, String, String)} for string as identifier
|
||||
* and see {@link RestResourceController#findOne(String, String, String)} for string as identifier
|
||||
*
|
||||
* @param apiCategory
|
||||
* @param model
|
||||
* @param uuid
|
||||
* @param projection
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = REGEX_REQUESTMAPPING_IDENTIFIER_AS_UUID)
|
||||
@SuppressWarnings("unchecked")
|
||||
public DSpaceResource<RestAddressableModel> findOne(@PathVariable String apiCategory, @PathVariable String model,
|
||||
@PathVariable UUID uuid,
|
||||
@RequestParam(required = false) String projection) {
|
||||
return findOneInternal(apiCategory, model, uuid, projection);
|
||||
@PathVariable UUID uuid) {
|
||||
return findOneInternal(apiCategory, model, uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,13 +213,10 @@ public class RestResourceController implements InitializingBean {
|
||||
* @param apiCategory
|
||||
* @param model
|
||||
* @param id
|
||||
* @param projection
|
||||
* @return
|
||||
*/
|
||||
private <ID extends Serializable> DSpaceResource<RestAddressableModel> findOneInternal(String apiCategory,
|
||||
String model, ID id,
|
||||
String projection) {
|
||||
checkModelPluralForm(apiCategory, model);
|
||||
String model, ID id) {
|
||||
DSpaceRestRepository<RestAddressableModel, ID> repository = utils.getResourceRepository(apiCategory, model);
|
||||
RestAddressableModel modelObject = null;
|
||||
try {
|
||||
@@ -235,9 +227,7 @@ public class RestResourceController implements InitializingBean {
|
||||
if (modelObject == null) {
|
||||
throw new ResourceNotFoundException(apiCategory + "." + model + " with id: " + id + " not found");
|
||||
}
|
||||
DSpaceResource result = repository.wrapResource(modelObject);
|
||||
linkService.addLinks(result);
|
||||
return result;
|
||||
return converter.toResource(modelObject);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -252,7 +242,6 @@ public class RestResourceController implements InitializingBean {
|
||||
* @param rel
|
||||
* @param page
|
||||
* @param assembler
|
||||
* @param projection
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = REGEX_REQUESTMAPPING_IDENTIFIER_AS_DIGIT + "/{rel}")
|
||||
@@ -260,9 +249,8 @@ public class RestResourceController implements InitializingBean {
|
||||
@PathVariable String apiCategory,
|
||||
@PathVariable String model, @PathVariable Integer id, @PathVariable String rel,
|
||||
Pageable page,
|
||||
PagedResourcesAssembler assembler,
|
||||
@RequestParam(required = false) String projection) {
|
||||
return findRelInternal(request, response, apiCategory, model, id, rel, page, assembler, projection);
|
||||
PagedResourcesAssembler assembler) {
|
||||
return findRelInternal(request, response, apiCategory, model, id, rel, page, assembler);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -278,7 +266,6 @@ public class RestResourceController implements InitializingBean {
|
||||
* @param rel
|
||||
* @param page
|
||||
* @param assembler
|
||||
* @param projection
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = REGEX_REQUESTMAPPING_IDENTIFIER_AS_STRING_VERSION_STRONG +
|
||||
@@ -287,9 +274,8 @@ public class RestResourceController implements InitializingBean {
|
||||
@PathVariable String apiCategory,
|
||||
@PathVariable String model, @PathVariable String id, @PathVariable String rel,
|
||||
Pageable page,
|
||||
PagedResourcesAssembler assembler,
|
||||
@RequestParam(required = false) String projection) {
|
||||
return findRelInternal(request, response, apiCategory, model, id, rel, page, assembler, projection);
|
||||
PagedResourcesAssembler assembler) {
|
||||
return findRelInternal(request, response, apiCategory, model, id, rel, page, assembler);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -304,7 +290,6 @@ public class RestResourceController implements InitializingBean {
|
||||
* @param rel
|
||||
* @param page
|
||||
* @param assembler
|
||||
* @param projection
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = REGEX_REQUESTMAPPING_IDENTIFIER_AS_UUID + "/{rel}")
|
||||
@@ -312,9 +297,8 @@ public class RestResourceController implements InitializingBean {
|
||||
@PathVariable String apiCategory,
|
||||
@PathVariable String model, @PathVariable UUID uuid, @PathVariable String rel,
|
||||
Pageable page,
|
||||
PagedResourcesAssembler assembler,
|
||||
@RequestParam(required = false) String projection) {
|
||||
return findRelInternal(request, response, apiCategory, model, uuid, rel, page, assembler, projection);
|
||||
PagedResourcesAssembler assembler) {
|
||||
return findRelInternal(request, response, apiCategory, model, uuid, rel, page, assembler);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -347,7 +331,6 @@ public class RestResourceController implements InitializingBean {
|
||||
* @param relid
|
||||
* @param page
|
||||
* @param assembler
|
||||
* @param projection
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = REGEX_REQUESTMAPPING_IDENTIFIER_AS_STRING_VERSION_STRONG +
|
||||
@@ -356,9 +339,8 @@ public class RestResourceController implements InitializingBean {
|
||||
@PathVariable String apiCategory,
|
||||
@PathVariable String model, @PathVariable String id, @PathVariable String rel,
|
||||
@PathVariable String relid,
|
||||
Pageable page, PagedResourcesAssembler assembler,
|
||||
@RequestParam(required = false) String projection) throws Throwable {
|
||||
return findRelEntryInternal(request, response, apiCategory, model, id, rel, relid, page, assembler, projection);
|
||||
Pageable page, PagedResourcesAssembler assembler) throws Throwable {
|
||||
return findRelEntryInternal(request, response, apiCategory, model, id, rel, relid, page, assembler);
|
||||
}
|
||||
|
||||
|
||||
@@ -443,8 +425,7 @@ public class RestResourceController implements InitializingBean {
|
||||
if (modelObject == null) {
|
||||
return ControllerUtils.toEmptyResponse(HttpStatus.CREATED);
|
||||
}
|
||||
DSpaceResource result = repository.wrapResource(modelObject);
|
||||
linkService.addLinks(result);
|
||||
DSpaceResource result = converter.toResource(modelObject);
|
||||
//TODO manage HTTPHeader
|
||||
return ControllerUtils.toResponseEntity(HttpStatus.CREATED, null, result);
|
||||
}
|
||||
@@ -476,8 +457,7 @@ public class RestResourceController implements InitializingBean {
|
||||
if (modelObject == null) {
|
||||
return ControllerUtils.toEmptyResponse(HttpStatus.CREATED);
|
||||
}
|
||||
DSpaceResource result = repository.wrapResource(modelObject);
|
||||
linkService.addLinks(result);
|
||||
DSpaceResource result = converter.toResource(modelObject);
|
||||
//TODO manage HTTPHeader
|
||||
return ControllerUtils.toResponseEntity(HttpStatus.CREATED, null, result);
|
||||
}
|
||||
@@ -515,8 +495,7 @@ public class RestResourceController implements InitializingBean {
|
||||
}
|
||||
|
||||
if (modelObject != null) {
|
||||
DSpaceResource result = repository.wrapResource(modelObject);
|
||||
linkService.addLinks(result);
|
||||
DSpaceResource result = converter.toResource(modelObject);
|
||||
return ControllerUtils.toResponseEntity(HttpStatus.CREATED, null, result);
|
||||
} else {
|
||||
return ControllerUtils.toEmptyResponse(HttpStatus.NO_CONTENT);
|
||||
@@ -607,8 +586,7 @@ public class RestResourceController implements InitializingBean {
|
||||
log.error(e.getMessage(), e);
|
||||
return ControllerUtils.toEmptyResponse(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
DSpaceResource result = repository.wrapResource(modelObject);
|
||||
linkService.addLinks(result);
|
||||
DSpaceResource result = converter.toResource(modelObject);
|
||||
return ControllerUtils.toResponseEntity(HttpStatus.CREATED, null, result);
|
||||
}
|
||||
|
||||
@@ -645,8 +623,7 @@ public class RestResourceController implements InitializingBean {
|
||||
|
||||
List<DSpaceResource> resources = new ArrayList<>();
|
||||
for (T modelObject : content) {
|
||||
DSpaceResource result = repository.wrapResource(modelObject);
|
||||
linkService.addLinks(result);
|
||||
DSpaceResource result = converter.toResource(modelObject);
|
||||
resources.add(result);
|
||||
}
|
||||
return ControllerUtils.toResponseEntity(HttpStatus.OK, null, Resources.wrap(resources));
|
||||
@@ -725,8 +702,7 @@ public class RestResourceController implements InitializingBean {
|
||||
log.error(e.getMessage(), e);
|
||||
throw e;
|
||||
}
|
||||
DSpaceResource result = repository.wrapResource(modelObject);
|
||||
linkService.addLinks(result);
|
||||
DSpaceResource result = converter.toResource(modelObject);
|
||||
//TODO manage HTTPHeader
|
||||
return ControllerUtils.toResponseEntity(HttpStatus.OK, null, result);
|
||||
|
||||
@@ -743,7 +719,6 @@ public class RestResourceController implements InitializingBean {
|
||||
* @param relid
|
||||
* @param page
|
||||
* @param assembler
|
||||
* @param projection
|
||||
* @return
|
||||
*/
|
||||
private <ID extends Serializable> ResourceSupport findRelEntryInternal(HttpServletRequest request,
|
||||
@@ -751,26 +726,24 @@ public class RestResourceController implements InitializingBean {
|
||||
String apiCategory, String model,
|
||||
String id, String rel, String relid,
|
||||
Pageable page,
|
||||
PagedResourcesAssembler assembler,
|
||||
String projection) throws Throwable {
|
||||
PagedResourcesAssembler assembler)
|
||||
throws Throwable {
|
||||
checkModelPluralForm(apiCategory, model);
|
||||
DSpaceRestRepository<RestAddressableModel, ID> repository = utils.getResourceRepository(apiCategory, model);
|
||||
Class<RestAddressableModel> domainClass = repository.getDomainClass();
|
||||
|
||||
LinkRest linkRest = utils.getLinkRest(rel, domainClass);
|
||||
LinkRest linkRest = utils.getClassLevelLinkRest(rel, domainClass);
|
||||
if (linkRest != null) {
|
||||
LinkRestRepository linkRepository = utils.getLinkResourceRepository(apiCategory, model, linkRest.name());
|
||||
Method linkMethod = repositoryUtils.getLinkMethod("getResource", linkRepository);
|
||||
|
||||
Method linkMethod = utils.requireMethod(linkRepository.getClass(), "getResource");
|
||||
try {
|
||||
Object object = linkMethod.invoke(linkRepository, request, id, relid, page, projection);
|
||||
Object object = linkMethod.invoke(linkRepository, request, id, relid, page, utils.obtainProjection());
|
||||
Link link = linkTo(this.getClass(), apiCategory, model).slash(id).slash(rel).slash(relid).withSelfRel();
|
||||
|
||||
List result = new ArrayList();
|
||||
result.add(object);
|
||||
PageImpl<RestAddressableModel> pageResult = new PageImpl(result, page, 1);
|
||||
Page<HALResource> halResources = pageResult.map(linkRepository::wrapResource);
|
||||
halResources.forEach(linkService::addLinks);
|
||||
Page<HALResource> halResources = pageResult.map(restObject -> converter.toResource(restObject));
|
||||
return assembler.toResource(halResources, link);
|
||||
} catch (InvocationTargetException e) {
|
||||
// This catch has been made to resolve the issue that caused AuthorizeDenied exceptions for the methods
|
||||
@@ -797,63 +770,52 @@ public class RestResourceController implements InitializingBean {
|
||||
* @param apiCategory
|
||||
* @param model
|
||||
* @param uuid
|
||||
* @param rel
|
||||
* @param page
|
||||
* @param assembler
|
||||
* @param projection
|
||||
* @return
|
||||
*/
|
||||
private <ID extends Serializable> ResourceSupport findRelInternal(HttpServletRequest request,
|
||||
HttpServletResponse response, String apiCategory,
|
||||
String model, ID uuid, String subpath,
|
||||
Pageable page, PagedResourcesAssembler assembler,
|
||||
String projection) {
|
||||
Pageable page,
|
||||
PagedResourcesAssembler assembler) {
|
||||
checkModelPluralForm(apiCategory, model);
|
||||
DSpaceRestRepository<RestAddressableModel, ID> repository = utils.getResourceRepository(apiCategory, model);
|
||||
Class<RestAddressableModel> domainClass = repository.getDomainClass();
|
||||
|
||||
LinkRest linkRest = utils.getLinkRest(subpath, domainClass);
|
||||
LinkRest linkRest = utils.getClassLevelLinkRest(subpath, domainClass);
|
||||
PagedResources<? extends HALResource> result;
|
||||
|
||||
if (linkRest != null) {
|
||||
LinkRestRepository linkRepository = utils.getLinkResourceRepository(apiCategory, model, linkRest.name());
|
||||
Method linkMethod = repositoryUtils.getLinkMethod(linkRest.method(), linkRepository);
|
||||
Method linkMethod = utils.requireMethod(linkRepository.getClass(), linkRest.method());
|
||||
try {
|
||||
if (Page.class.isAssignableFrom(linkMethod.getReturnType())) {
|
||||
Page<? extends RestModel> pageResult = (Page<? extends RestAddressableModel>) linkMethod
|
||||
.invoke(linkRepository, request, uuid, page, utils.obtainProjection(true));
|
||||
|
||||
if (linkMethod == null) {
|
||||
// TODO custom exception
|
||||
throw new RuntimeException(
|
||||
"Method for relation " + subpath + " not found: " + linkRest.name() + ":" + linkRest.method());
|
||||
} else {
|
||||
try {
|
||||
if (Page.class.isAssignableFrom(linkMethod.getReturnType())) {
|
||||
Page<? extends RestModel> pageResult = (Page<? extends RestAddressableModel>) linkMethod
|
||||
.invoke(linkRepository, request, uuid, page, projection);
|
||||
|
||||
Link link = null;
|
||||
String querystring = request.getQueryString();
|
||||
if (querystring != null && querystring.length() > 0) {
|
||||
link = linkTo(this.getClass(), apiCategory, model).slash(uuid)
|
||||
.slash(subpath + '?' + querystring).withSelfRel();
|
||||
} else {
|
||||
link = linkTo(this.getClass(), apiCategory, model).slash(uuid).slash(subpath).withSelfRel();
|
||||
}
|
||||
|
||||
Page<HALResource> halResources = pageResult.map(linkRepository::wrapResource);
|
||||
halResources.forEach(linkService::addLinks);
|
||||
|
||||
return assembler.toResource(halResources, link);
|
||||
Link link = null;
|
||||
String querystring = request.getQueryString();
|
||||
if (querystring != null && querystring.length() > 0) {
|
||||
link = linkTo(this.getClass(), apiCategory, model).slash(uuid)
|
||||
.slash(subpath + '?' + querystring).withSelfRel();
|
||||
} else {
|
||||
RestModel object = (RestModel) linkMethod.invoke(linkRepository, request, uuid, page,
|
||||
projection);
|
||||
Link link = linkTo(this.getClass(), apiCategory, model).slash(uuid).slash(subpath)
|
||||
.withSelfRel();
|
||||
HALResource tmpresult = linkRepository.wrapResource(object);
|
||||
tmpresult.add(link);
|
||||
return tmpresult;
|
||||
link = linkTo(this.getClass(), apiCategory, model).slash(uuid).slash(subpath).withSelfRel();
|
||||
}
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
|
||||
Page<HALResource> halResources = pageResult.map(object -> converter.toResource(object));
|
||||
return assembler.toResource(halResources, link);
|
||||
} else {
|
||||
RestModel object = (RestModel) linkMethod.invoke(linkRepository, request, uuid, page,
|
||||
utils.obtainProjection());
|
||||
Link link = linkTo(this.getClass(), apiCategory, model).slash(uuid).slash(subpath)
|
||||
.withSelfRel();
|
||||
HALResource tmpresult = converter.toResource(object);
|
||||
tmpresult.add(link);
|
||||
return tmpresult;
|
||||
}
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
RestAddressableModel modelObject = repository.findOne(uuid);
|
||||
@@ -862,8 +824,7 @@ public class RestResourceController implements InitializingBean {
|
||||
throw new ResourceNotFoundException(apiCategory + "." + model + " with id: " + uuid + " not found");
|
||||
}
|
||||
|
||||
DSpaceResource resource = repository.wrapResource(modelObject, subpath);
|
||||
linkService.addLinks(resource);
|
||||
DSpaceResource resource = converter.toResource(modelObject);
|
||||
|
||||
String rel = null;
|
||||
|
||||
@@ -904,16 +865,7 @@ public class RestResourceController implements InitializingBean {
|
||||
.getResourceRepository(fullList.get(0).getCategory(), fullList.get(0).getType());
|
||||
PageImpl<RestAddressableModel> pageResult = new PageImpl(fullList.subList(start, end), page,
|
||||
fullList.size());
|
||||
result = assembler.toResource(pageResult.map(resourceRepository::wrapResource));
|
||||
|
||||
for (Resource subObj : result) {
|
||||
if (subObj.getContent() instanceof HALResource) {
|
||||
linkService.addLinks((HALResource) subObj.getContent());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
|
||||
return assembler.toResource(pageResult.map(converter::toResource));
|
||||
} else {
|
||||
if (resource.getEmbeddedResources().get(rel) == null) {
|
||||
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
|
||||
@@ -930,7 +882,6 @@ public class RestResourceController implements InitializingBean {
|
||||
* @param model
|
||||
* @param page
|
||||
* @param assembler
|
||||
* @param projection
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@@ -939,18 +890,15 @@ public class RestResourceController implements InitializingBean {
|
||||
@PathVariable String model,
|
||||
Pageable page,
|
||||
PagedResourcesAssembler assembler,
|
||||
@RequestParam(required = false)
|
||||
String projection,
|
||||
HttpServletResponse response) {
|
||||
DSpaceRestRepository<T, ?> repository = utils.getResourceRepository(apiCategory, model);
|
||||
Link link = linkTo(methodOn(this.getClass(), apiCategory, model).findAll(apiCategory, model,
|
||||
page, assembler, projection, response))
|
||||
page, assembler, response))
|
||||
.withSelfRel();
|
||||
|
||||
Page<DSpaceResource<T>> resources;
|
||||
try {
|
||||
resources = repository.findAll(page).map(repository::wrapResource);
|
||||
resources.forEach(linkService::addLinks);
|
||||
resources = repository.findAll(page).map(converter::toResource);
|
||||
} catch (PaginationException pe) {
|
||||
resources = new PageImpl<DSpaceResource<T>>(new ArrayList<DSpaceResource<T>>(), page, pe.getTotal());
|
||||
} catch (RepositoryMethodNotImplementedException mne) {
|
||||
@@ -1029,18 +977,15 @@ public class RestResourceController implements InitializingBean {
|
||||
if (searchResult == null) {
|
||||
resources = new PageImpl(new ArrayList(), pageable, 0);
|
||||
} else {
|
||||
resources = ((Page<T>) searchResult).map(repository::wrapResource);
|
||||
resources = ((Page<T>) searchResult).map(converter::toResource);
|
||||
}
|
||||
resources.forEach(linkService::addLinks);
|
||||
result = assembler.toResource(resources, link);
|
||||
} else {
|
||||
if (searchResult == null) {
|
||||
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
|
||||
return null;
|
||||
}
|
||||
DSpaceResource<T> dsResource = repository.wrapResource((T) searchResult);
|
||||
linkService.addLinks(dsResource);
|
||||
result = dsResource;
|
||||
return converter.toResource((T) searchResult);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1189,9 +1134,7 @@ public class RestResourceController implements InitializingBean {
|
||||
if (modelObject == null) {
|
||||
throw new ResourceNotFoundException(apiCategory + "." + model + " with id: " + id + " not found");
|
||||
}
|
||||
DSpaceResource result = repository.wrapResource(modelObject);
|
||||
linkService.addLinks(result);
|
||||
return result;
|
||||
return converter.toResource(modelObject);
|
||||
|
||||
}
|
||||
/**
|
||||
@@ -1214,9 +1157,6 @@ public class RestResourceController implements InitializingBean {
|
||||
if (modelObject == null) {
|
||||
throw new ResourceNotFoundException(apiCategory + "." + model + " with id: " + id + " not found");
|
||||
}
|
||||
DSpaceResource result = repository.wrapResource(modelObject);
|
||||
linkService.addLinks(result);
|
||||
return result;
|
||||
|
||||
return converter.toResource(modelObject);
|
||||
}
|
||||
}
|
||||
|
@@ -9,8 +9,8 @@ package org.dspace.app.rest;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.dspace.app.rest.converter.ConverterService;
|
||||
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;
|
||||
@@ -39,13 +39,11 @@ public class RootRestResourceController {
|
||||
@Autowired
|
||||
RootRestRepository rootRestRepository;
|
||||
|
||||
@Autowired
|
||||
ConverterService converter;
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
public RootResource listDefinedEndpoint(HttpServletRequest request) {
|
||||
|
||||
RootRest rootRest = rootRestRepository.getRoot();
|
||||
RootResource rootResource = new RootResource(rootRest);
|
||||
halLinkService.addLinks(rootResource);
|
||||
|
||||
return rootResource;
|
||||
return converter.toResource(rootRestRepository.getRoot());
|
||||
}
|
||||
}
|
||||
|
@@ -9,12 +9,11 @@ package org.dspace.app.rest;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.app.rest.link.HalLinkService;
|
||||
import org.dspace.app.rest.converter.ConverterService;
|
||||
import org.dspace.app.rest.model.ProcessRest;
|
||||
import org.dspace.app.rest.model.ScriptRest;
|
||||
import org.dspace.app.rest.model.hateoas.ProcessResource;
|
||||
import org.dspace.app.rest.repository.ScriptRestRepository;
|
||||
import org.dspace.app.rest.utils.Utils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.rest.webmvc.ControllerUtils;
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
@@ -35,15 +34,12 @@ public class ScriptProcessesController {
|
||||
|
||||
private static final Logger log = LogManager.getLogger();
|
||||
|
||||
@Autowired
|
||||
private ConverterService converter;
|
||||
|
||||
@Autowired
|
||||
private ScriptRestRepository scriptRestRepository;
|
||||
|
||||
@Autowired
|
||||
private HalLinkService halLinkService;
|
||||
|
||||
@Autowired
|
||||
private Utils utils;
|
||||
|
||||
/**
|
||||
* This method can be called by sending a POST request to the system/scripts/{name}/processes endpoint
|
||||
* This will start a process for the script that matches the given name
|
||||
@@ -59,8 +55,7 @@ public class ScriptProcessesController {
|
||||
log.trace("Starting Process for Script with name: " + scriptName);
|
||||
}
|
||||
ProcessRest processRest = scriptRestRepository.startProcess(scriptName);
|
||||
ProcessResource processResource = new ProcessResource(processRest, utils, null);
|
||||
halLinkService.addLinks(processResource);
|
||||
ProcessResource processResource = converter.toResource(processRest);
|
||||
return ControllerUtils.toResponseEntity(HttpStatus.ACCEPTED, null, processResource);
|
||||
}
|
||||
|
||||
|
@@ -10,6 +10,7 @@ package org.dspace.app.rest;
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.dspace.app.rest.converter.ConverterService;
|
||||
import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException;
|
||||
import org.dspace.app.rest.link.HalLinkService;
|
||||
import org.dspace.app.rest.model.RestAddressableModel;
|
||||
@@ -47,6 +48,9 @@ public class StatisticsRestController implements InitializingBean {
|
||||
@Autowired
|
||||
private HalLinkService halLinkService;
|
||||
|
||||
@Autowired
|
||||
private ConverterService converter;
|
||||
|
||||
@Autowired
|
||||
private StatisticsRestRepository statisticsRestRepository;
|
||||
|
||||
@@ -65,12 +69,10 @@ public class StatisticsRestController implements InitializingBean {
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
public StatisticsSupportResource getStatisticsSupport() throws Exception {
|
||||
|
||||
StatisticsSupportRest statisticsSupportRest = statisticsRestRepository.getStatisticsSupport();
|
||||
StatisticsSupportResource statisticsSupportResource = new StatisticsSupportResource(statisticsSupportRest);
|
||||
halLinkService.addLinks(statisticsSupportResource);
|
||||
return statisticsSupportResource;
|
||||
return converter.toResource(statisticsSupportRest);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/viewevents/{uuid}")
|
||||
public PagedResources<ViewEventResource> getViewEvent(@PathVariable(name = "uuid") UUID uuid) throws Exception {
|
||||
throw new RepositoryMethodNotImplementedException("No implementation found; Method not allowed!", "");
|
||||
@@ -93,13 +95,13 @@ public class StatisticsRestController implements InitializingBean {
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/viewevents")
|
||||
public ResponseEntity<ResourceSupport> postViewEvent() throws Exception {
|
||||
ViewEventResource result = new ViewEventResource(viewEventRestRepository.createViewEvent(), utils);
|
||||
ViewEventResource result = converter.toResource(viewEventRestRepository.createViewEvent());
|
||||
return ControllerUtils.toResponseEntity(HttpStatus.CREATED, null, result);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/searchevents")
|
||||
public ResponseEntity<ResourceSupport> postSearchEvent() throws Exception {
|
||||
SearchEventResource result = new SearchEventResource(searchEventRestRepository.createSearchEvent(), utils);
|
||||
SearchEventResource result = converter.toResource(searchEventRestRepository.createSearchEvent());
|
||||
return ControllerUtils.toResponseEntity(HttpStatus.CREATED, null, result);
|
||||
}
|
||||
|
||||
|
@@ -14,14 +14,14 @@ import java.net.URI;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.rest.converter.GenericDSpaceObjectConverter;
|
||||
import org.dspace.app.rest.converter.ConverterService;
|
||||
import org.dspace.app.rest.model.DSpaceObjectRest;
|
||||
import org.dspace.app.rest.utils.ContextUtil;
|
||||
import org.dspace.app.rest.utils.Utils;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.service.DSpaceObjectService;
|
||||
@@ -57,6 +57,9 @@ public class UUIDLookupRestController implements InitializingBean {
|
||||
@Autowired
|
||||
private ContentServiceFactory contentServiceFactory;
|
||||
|
||||
@Autowired
|
||||
private Utils utils;
|
||||
|
||||
private static final Logger log =
|
||||
Logger.getLogger(UUIDLookupRestController.class);
|
||||
|
||||
@@ -64,7 +67,7 @@ public class UUIDLookupRestController implements InitializingBean {
|
||||
private DiscoverableEndpointsService discoverableEndpointsService;
|
||||
|
||||
@Autowired
|
||||
private GenericDSpaceObjectConverter converter;
|
||||
private ConverterService converter;
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
@@ -92,7 +95,7 @@ public class UUIDLookupRestController implements InitializingBean {
|
||||
.getDSpaceObjectServices()) {
|
||||
DSpaceObject dso = dSpaceObjectService.find(context, uuid);
|
||||
if (dso != null) {
|
||||
DSpaceObjectRest dsor = converter.convert(dso);
|
||||
DSpaceObjectRest dsor = converter.toRest(dso, utils.obtainProjection());
|
||||
URI link = linkTo(dsor.getController(), dsor.getCategory(), dsor.getTypePlural())
|
||||
.slash(dsor.getId()).toUri();
|
||||
response.setStatus(HttpServletResponse.SC_FOUND);
|
||||
|
@@ -17,6 +17,7 @@ import org.dspace.app.rest.model.AInprogressSubmissionRest;
|
||||
import org.dspace.app.rest.model.ErrorRest;
|
||||
import org.dspace.app.rest.model.SubmissionDefinitionRest;
|
||||
import org.dspace.app.rest.model.SubmissionSectionRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.app.rest.submit.AbstractRestProcessingStep;
|
||||
import org.dspace.app.rest.submit.SubmissionService;
|
||||
import org.dspace.app.util.SubmissionConfigReader;
|
||||
@@ -47,22 +48,13 @@ public abstract class AInprogressItemConverter<T extends InProgressSubmission<ID
|
||||
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(AInprogressItemConverter.class);
|
||||
|
||||
@Autowired
|
||||
private EPersonConverter epersonConverter;
|
||||
|
||||
@Autowired
|
||||
private ItemConverter itemConverter;
|
||||
|
||||
@Autowired
|
||||
private CollectionConverter collectionConverter;
|
||||
|
||||
protected SubmissionConfigReader submissionConfigReader;
|
||||
|
||||
@Autowired
|
||||
private SubmissionDefinitionConverter submissionDefinitionConverter;
|
||||
private ConverterService converter;
|
||||
|
||||
@Autowired
|
||||
private SubmissionSectionConverter submissionSectionConverter;
|
||||
|
||||
protected SubmissionConfigReader submissionConfigReader;
|
||||
|
||||
@Autowired
|
||||
SubmissionService submissionService;
|
||||
|
||||
@@ -70,7 +62,7 @@ public abstract class AInprogressItemConverter<T extends InProgressSubmission<ID
|
||||
submissionConfigReader = new SubmissionConfigReader();
|
||||
}
|
||||
|
||||
protected void fillFromModel(T obj, R witem) {
|
||||
protected void fillFromModel(T obj, R witem, Projection projection) {
|
||||
Collection collection = obj.getCollection();
|
||||
Item item = obj.getItem();
|
||||
EPerson submitter = null;
|
||||
@@ -81,17 +73,17 @@ public abstract class AInprogressItemConverter<T extends InProgressSubmission<ID
|
||||
}
|
||||
|
||||
witem.setId(obj.getID());
|
||||
witem.setCollection(collection != null ? collectionConverter.convert(collection) : null);
|
||||
witem.setItem(itemConverter.convert(item));
|
||||
witem.setSubmitter(epersonConverter.convert(submitter));
|
||||
witem.setCollection(collection != null ? converter.toRest(collection, projection) : null);
|
||||
witem.setItem(converter.toRest(item, projection));
|
||||
witem.setSubmitter(converter.toRest(submitter, projection));
|
||||
|
||||
// 1. retrieve the submission definition
|
||||
// 2. iterate over the submission section to allow to plugin additional
|
||||
// info
|
||||
|
||||
if (collection != null) {
|
||||
SubmissionDefinitionRest def = submissionDefinitionConverter
|
||||
.convert(submissionConfigReader.getSubmissionConfigByCollection(collection.getHandle()));
|
||||
SubmissionDefinitionRest def = converter.toRest(
|
||||
submissionConfigReader.getSubmissionConfigByCollection(collection.getHandle()), projection);
|
||||
witem.setSubmissionDefinition(def);
|
||||
for (SubmissionSectionRest sections : def.getPanels()) {
|
||||
SubmissionStepConfig stepConfig = submissionSectionConverter.toModel(sections);
|
||||
@@ -150,4 +142,4 @@ public abstract class AInprogressItemConverter<T extends InProgressSubmission<ID
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -7,8 +7,8 @@
|
||||
*/
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import org.apache.commons.lang3.NotImplementedException;
|
||||
import org.dspace.app.rest.model.AuthorityEntryRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.app.rest.utils.AuthorityUtils;
|
||||
import org.dspace.content.authority.Choice;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -17,7 +17,7 @@ import org.springframework.stereotype.Component;
|
||||
* This is the converter from/to the Choice in the DSpace API data
|
||||
* model and the REST data model.
|
||||
*
|
||||
* TODO please do not use this convert but use the wrapper {@link AuthorityUtils#convertEntry(Choice, String)}}
|
||||
* TODO please do not use this convert but use the wrapper {@link AuthorityUtils#convertEntry(Choice, String, String)}
|
||||
*
|
||||
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
||||
*/
|
||||
@@ -25,8 +25,9 @@ import org.springframework.stereotype.Component;
|
||||
public class AuthorityEntryRestConverter implements DSpaceConverter<Choice, AuthorityEntryRest> {
|
||||
|
||||
@Override
|
||||
public AuthorityEntryRest fromModel(Choice choice) {
|
||||
public AuthorityEntryRest convert(Choice choice, Projection projection) {
|
||||
AuthorityEntryRest entry = new AuthorityEntryRest();
|
||||
entry.setProjection(projection);
|
||||
entry.setValue(choice.value);
|
||||
entry.setDisplay(choice.label);
|
||||
entry.setId(choice.authority);
|
||||
@@ -35,7 +36,7 @@ public class AuthorityEntryRestConverter implements DSpaceConverter<Choice, Auth
|
||||
}
|
||||
|
||||
@Override
|
||||
public Choice toModel(AuthorityEntryRest obj) {
|
||||
throw new NotImplementedException("Method not implemented");
|
||||
public Class<Choice> getModelClass() {
|
||||
return Choice.class;
|
||||
}
|
||||
}
|
||||
|
@@ -7,8 +7,8 @@
|
||||
*/
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import org.apache.commons.lang3.NotImplementedException;
|
||||
import org.dspace.app.rest.model.AuthorityRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.app.rest.utils.AuthorityUtils;
|
||||
import org.dspace.content.authority.ChoiceAuthority;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -18,7 +18,7 @@ import org.springframework.stereotype.Component;
|
||||
* model and the REST data model
|
||||
*
|
||||
* TODO please do not use this convert but use the wrapper
|
||||
* {@link AuthorityUtils#convertAuthority(ChoiceAuthority, String)}
|
||||
* {@link AuthorityUtils#convertAuthority(ChoiceAuthority, String, String)}
|
||||
*
|
||||
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
||||
*/
|
||||
@@ -26,8 +26,9 @@ import org.springframework.stereotype.Component;
|
||||
public class AuthorityRestConverter implements DSpaceConverter<ChoiceAuthority, AuthorityRest> {
|
||||
|
||||
@Override
|
||||
public AuthorityRest fromModel(ChoiceAuthority step) {
|
||||
public AuthorityRest convert(ChoiceAuthority step, Projection projection) {
|
||||
AuthorityRest authorityRest = new AuthorityRest();
|
||||
authorityRest.setProjection(projection);
|
||||
authorityRest.setHierarchical(step.isHierarchical());
|
||||
authorityRest.setScrollable(step.isScrollable());
|
||||
authorityRest.setIdentifier(step.hasIdentifier());
|
||||
@@ -35,7 +36,7 @@ public class AuthorityRestConverter implements DSpaceConverter<ChoiceAuthority,
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChoiceAuthority toModel(AuthorityRest obj) {
|
||||
throw new NotImplementedException("Method not implemented");
|
||||
public Class<ChoiceAuthority> getModelClass() {
|
||||
return ChoiceAuthority.class;
|
||||
}
|
||||
}
|
||||
|
@@ -10,9 +10,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;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.content.Bitstream;
|
||||
import org.dspace.content.Bundle;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -25,19 +25,14 @@ import org.springframework.stereotype.Component;
|
||||
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||
*/
|
||||
@Component
|
||||
public class BitstreamConverter
|
||||
extends DSpaceObjectConverter<org.dspace.content.Bitstream, org.dspace.app.rest.model.BitstreamRest> {
|
||||
@Autowired(required = true)
|
||||
BitstreamFormatConverter bfConverter;
|
||||
public class BitstreamConverter extends DSpaceObjectConverter<Bitstream, BitstreamRest> {
|
||||
|
||||
@Autowired
|
||||
ConverterService converter;
|
||||
|
||||
@Override
|
||||
public org.dspace.content.Bitstream toModel(org.dspace.app.rest.model.BitstreamRest obj) {
|
||||
return super.toModel(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BitstreamRest fromModel(org.dspace.content.Bitstream obj) {
|
||||
BitstreamRest b = super.fromModel(obj);
|
||||
public BitstreamRest convert(org.dspace.content.Bitstream obj, Projection projection) {
|
||||
BitstreamRest b = super.convert(obj, projection);
|
||||
b.setSequenceId(obj.getSequenceID());
|
||||
List<Bundle> bundles = null;
|
||||
try {
|
||||
@@ -53,14 +48,11 @@ public class BitstreamConverter
|
||||
checksum.setCheckSumAlgorithm(obj.getChecksumAlgorithm());
|
||||
checksum.setValue(obj.getChecksum());
|
||||
b.setCheckSum(checksum);
|
||||
BitstreamFormatRest format = null;
|
||||
try {
|
||||
format = bfConverter.fromModel(obj.getFormat(null));
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
b.setFormat(converter.toRest(obj.getFormat(null), projection));
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
b.setFormat(format);
|
||||
b.setSizeBytes(obj.getSizeBytes());
|
||||
return b;
|
||||
}
|
||||
@@ -71,7 +63,7 @@ public class BitstreamConverter
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<Bitstream> getModelClass() {
|
||||
public Class<Bitstream> getModelClass() {
|
||||
return Bitstream.class;
|
||||
}
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import org.dspace.app.rest.model.BitstreamFormatRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.content.BitstreamFormat;
|
||||
import org.dspace.content.service.BitstreamFormatService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -26,8 +27,9 @@ public class BitstreamFormatConverter implements DSpaceConverter<BitstreamFormat
|
||||
BitstreamFormatService bitstreamFormatService;
|
||||
|
||||
@Override
|
||||
public BitstreamFormatRest fromModel(BitstreamFormat obj) {
|
||||
public BitstreamFormatRest convert(BitstreamFormat obj, Projection projection) {
|
||||
BitstreamFormatRest bf = new BitstreamFormatRest();
|
||||
bf.setProjection(projection);
|
||||
bf.setId(obj.getID());
|
||||
bf.setShortDescription(obj.getShortDescription());
|
||||
bf.setDescription(obj.getDescription());
|
||||
@@ -43,8 +45,7 @@ public class BitstreamFormatConverter implements DSpaceConverter<BitstreamFormat
|
||||
}
|
||||
|
||||
@Override
|
||||
public BitstreamFormat toModel(BitstreamFormatRest obj) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
public Class<BitstreamFormat> getModelClass() {
|
||||
return BitstreamFormat.class;
|
||||
}
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.app.rest.model.BrowseIndexRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.browse.BrowseIndex;
|
||||
import org.dspace.sort.SortException;
|
||||
import org.dspace.sort.SortOption;
|
||||
@@ -24,9 +25,11 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component
|
||||
public class BrowseIndexConverter implements DSpaceConverter<BrowseIndex, BrowseIndexRest> {
|
||||
|
||||
@Override
|
||||
public BrowseIndexRest fromModel(BrowseIndex obj) {
|
||||
public BrowseIndexRest convert(BrowseIndex obj, Projection projection) {
|
||||
BrowseIndexRest bir = new BrowseIndexRest();
|
||||
bir.setProjection(projection);
|
||||
bir.setId(obj.getName());
|
||||
bir.setOrder(obj.getDefaultOrder());
|
||||
bir.setMetadataBrowse(obj.isMetadataIndex());
|
||||
@@ -53,7 +56,7 @@ public class BrowseIndexConverter implements DSpaceConverter<BrowseIndex, Browse
|
||||
}
|
||||
|
||||
@Override
|
||||
public BrowseIndex toModel(BrowseIndexRest obj) {
|
||||
return null;
|
||||
public Class<BrowseIndex> getModelClass() {
|
||||
return BrowseIndex.class;
|
||||
}
|
||||
}
|
||||
|
@@ -11,43 +11,38 @@ import java.util.stream.Collectors;
|
||||
|
||||
import org.dspace.app.rest.model.BitstreamRest;
|
||||
import org.dspace.app.rest.model.BundleRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.content.Bundle;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class BundleConverter
|
||||
extends DSpaceObjectConverter<org.dspace.content.Bundle, org.dspace.app.rest.model.BundleRest> {
|
||||
extends DSpaceObjectConverter<Bundle, BundleRest> {
|
||||
|
||||
@Autowired
|
||||
BitstreamConverter bitstreamConverter;
|
||||
@Override
|
||||
public BundleRest convert(Bundle bundle, Projection projection) {
|
||||
BundleRest bundleRest = super.convert(bundle, projection);
|
||||
|
||||
bundleRest.setBitstreams(bundle.getBitstreams()
|
||||
.stream()
|
||||
.map(x -> (BitstreamRest) converter.toRest(x, projection))
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
if (bundle.getPrimaryBitstream() != null) {
|
||||
BitstreamRest primaryBitstreamRest = converter.toRest(bundle.getPrimaryBitstream(), projection);
|
||||
bundleRest.setPrimaryBitstream(primaryBitstreamRest);
|
||||
}
|
||||
|
||||
return bundleRest;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BundleRest newInstance() {
|
||||
return new BundleRest();
|
||||
}
|
||||
|
||||
protected Class<Bundle> getModelClass() {
|
||||
@Override
|
||||
public Class<Bundle> getModelClass() {
|
||||
return Bundle.class;
|
||||
}
|
||||
|
||||
public BundleRest fromModel(Bundle obj) {
|
||||
BundleRest bundle = (BundleRest) super.fromModel(obj);
|
||||
|
||||
bundle.setBitstreams(obj.getBitstreams()
|
||||
.stream()
|
||||
.map(x -> bitstreamConverter.fromModel(x))
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
if (obj.getPrimaryBitstream() != null) {
|
||||
BitstreamRest primaryBitstreamRest = bitstreamConverter.fromModel(obj.getPrimaryBitstream());
|
||||
bundle.setPrimaryBitstream(primaryBitstreamRest);
|
||||
}
|
||||
|
||||
return bundle;
|
||||
}
|
||||
|
||||
public Bundle toModel(BundleRest obj) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -8,6 +8,7 @@
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import org.dspace.app.rest.model.ClaimedTaskRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.discovery.IndexableObject;
|
||||
import org.dspace.xmlworkflow.storedcomponents.ClaimedTask;
|
||||
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
|
||||
@@ -22,30 +23,27 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component
|
||||
public class ClaimedTaskConverter
|
||||
implements IndexableObjectConverter<ClaimedTask, org.dspace.app.rest.model.ClaimedTaskRest> {
|
||||
implements IndexableObjectConverter<ClaimedTask, ClaimedTaskRest> {
|
||||
|
||||
@Autowired
|
||||
private WorkflowItemConverter workflowItemConverter;
|
||||
|
||||
@Autowired
|
||||
private EPersonConverter epersonConverter;
|
||||
private ConverterService converter;
|
||||
|
||||
@Override
|
||||
public ClaimedTaskRest fromModel(ClaimedTask obj) {
|
||||
public ClaimedTaskRest convert(ClaimedTask obj, Projection projection) {
|
||||
ClaimedTaskRest taskRest = new ClaimedTaskRest();
|
||||
|
||||
taskRest.setProjection(projection);
|
||||
XmlWorkflowItem witem = obj.getWorkflowItem();
|
||||
taskRest.setId(obj.getID());
|
||||
taskRest.setWorkflowitem(workflowItemConverter.convert(witem));
|
||||
taskRest.setWorkflowitem(converter.toRest(witem, projection));
|
||||
taskRest.setAction(obj.getActionID());
|
||||
taskRest.setStep(obj.getStepID());
|
||||
taskRest.setOwner(epersonConverter.convert(obj.getOwner()));
|
||||
taskRest.setOwner(converter.toRest(obj.getOwner(), projection));
|
||||
return taskRest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClaimedTask toModel(ClaimedTaskRest obj) {
|
||||
return null;
|
||||
public Class<ClaimedTask> getModelClass() {
|
||||
return ClaimedTask.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,4 +51,4 @@ public class ClaimedTaskConverter
|
||||
return object instanceof ClaimedTask;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.app.rest.model.CollectionRest;
|
||||
import org.dspace.app.rest.model.ResourcePolicyRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.app.rest.utils.ContextUtil;
|
||||
import org.dspace.authorize.ResourcePolicy;
|
||||
import org.dspace.authorize.service.AuthorizeService;
|
||||
@@ -44,35 +45,28 @@ public class CollectionConverter
|
||||
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(CollectionConverter.class);
|
||||
|
||||
@Autowired
|
||||
private BitstreamConverter bitstreamConverter;
|
||||
private ConverterService converter;
|
||||
@Autowired
|
||||
private CollectionService collectionService;
|
||||
@Autowired
|
||||
private RequestService requestService;
|
||||
@Autowired
|
||||
private AuthorizeService authorizeService;
|
||||
@Autowired
|
||||
private ResourcePolicyConverter resourcePolicyConverter;
|
||||
|
||||
@Override
|
||||
public org.dspace.content.Collection toModel(org.dspace.app.rest.model.CollectionRest obj) {
|
||||
return (org.dspace.content.Collection) super.toModel(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionRest fromModel(org.dspace.content.Collection obj) {
|
||||
CollectionRest col = (CollectionRest) super.fromModel(obj);
|
||||
public CollectionRest convert(org.dspace.content.Collection obj, Projection projection) {
|
||||
CollectionRest col = super.convert(obj, projection);
|
||||
Bitstream logo = obj.getLogo();
|
||||
if (logo != null) {
|
||||
col.setLogo(bitstreamConverter.convert(logo));
|
||||
col.setLogo(converter.toRest(logo, projection));
|
||||
}
|
||||
|
||||
col.setDefaultAccessConditions(getDefaultBitstreamPoliciesForCollection(obj.getID()));
|
||||
col.setDefaultAccessConditions(getDefaultBitstreamPoliciesForCollection(obj.getID(), projection));
|
||||
|
||||
return col;
|
||||
}
|
||||
|
||||
private List<ResourcePolicyRest> getDefaultBitstreamPoliciesForCollection(UUID uuid) {
|
||||
private List<ResourcePolicyRest> getDefaultBitstreamPoliciesForCollection(UUID uuid, Projection projection) {
|
||||
|
||||
Context context = null;
|
||||
Request currentRequest = requestService.getCurrentRequest();
|
||||
@@ -95,7 +89,7 @@ public class CollectionConverter
|
||||
List<ResourcePolicyRest> results = new ArrayList<ResourcePolicyRest>();
|
||||
|
||||
for (ResourcePolicy pp : defaultCollectionPolicies) {
|
||||
ResourcePolicyRest accessCondition = resourcePolicyConverter.convert(pp);
|
||||
ResourcePolicyRest accessCondition = converter.toRest(pp, projection);
|
||||
if (accessCondition != null) {
|
||||
results.add(accessCondition);
|
||||
}
|
||||
@@ -109,7 +103,7 @@ public class CollectionConverter
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<org.dspace.content.Collection> getModelClass() {
|
||||
public Class<org.dspace.content.Collection> getModelClass() {
|
||||
return org.dspace.content.Collection.class;
|
||||
}
|
||||
|
||||
|
@@ -12,6 +12,7 @@ import java.util.List;
|
||||
|
||||
import org.dspace.app.rest.model.CollectionRest;
|
||||
import org.dspace.app.rest.model.CommunityRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.content.Bitstream;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
@@ -31,38 +32,29 @@ public class CommunityConverter
|
||||
implements IndexableObjectConverter<Community, CommunityRest> {
|
||||
|
||||
@Autowired
|
||||
private BitstreamConverter bitstreamConverter;
|
||||
|
||||
@Autowired
|
||||
private CollectionConverter collectionConverter;
|
||||
private ConverterService converter;
|
||||
|
||||
@Override
|
||||
public org.dspace.content.Community toModel(org.dspace.app.rest.model.CommunityRest obj) {
|
||||
return (org.dspace.content.Community) super.toModel(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommunityRest fromModel(org.dspace.content.Community obj) {
|
||||
CommunityRest com = (CommunityRest) super.fromModel(obj);
|
||||
public CommunityRest convert(org.dspace.content.Community obj, Projection projection) {
|
||||
CommunityRest com = super.convert(obj, projection);
|
||||
Bitstream logo = obj.getLogo();
|
||||
if (logo != null) {
|
||||
com.setLogo(bitstreamConverter.convert(logo));
|
||||
com.setLogo(converter.toRest(logo, projection));
|
||||
}
|
||||
List<Collection> collections = obj.getCollections();
|
||||
List<CollectionRest> collectionsRest = new ArrayList<CollectionRest>();
|
||||
List<CollectionRest> collectionsRest = new ArrayList<>();
|
||||
if (collections != null) {
|
||||
for (Collection col : collections) {
|
||||
CollectionRest colrest = collectionConverter.fromModel(col);
|
||||
collectionsRest.add(colrest);
|
||||
collectionsRest.add(converter.toRest(col, projection));
|
||||
}
|
||||
}
|
||||
com.setCollections(collectionsRest);
|
||||
|
||||
List<Community> subCommunities = obj.getSubcommunities();
|
||||
List<CommunityRest> communityRest = new ArrayList<CommunityRest>();
|
||||
List<CommunityRest> communityRest = new ArrayList<>();
|
||||
if (subCommunities != null) {
|
||||
for (Community scom : subCommunities) {
|
||||
CommunityRest scomrest = this.fromModel(scom);
|
||||
CommunityRest scomrest = this.convert(scom, projection);
|
||||
communityRest.add(scomrest);
|
||||
}
|
||||
}
|
||||
@@ -77,7 +69,7 @@ public class CommunityConverter
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<org.dspace.content.Community> getModelClass() {
|
||||
public Class<org.dspace.content.Community> getModelClass() {
|
||||
return org.dspace.content.Community.class;
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,303 @@
|
||||
/**
|
||||
* 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.converter;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.rest.link.HalLinkFactory;
|
||||
import org.dspace.app.rest.link.HalLinkService;
|
||||
import org.dspace.app.rest.model.RestAddressableModel;
|
||||
import org.dspace.app.rest.model.RestModel;
|
||||
import org.dspace.app.rest.model.hateoas.HALResource;
|
||||
import org.dspace.app.rest.projection.DefaultProjection;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.app.rest.utils.Utils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
|
||||
import org.springframework.core.type.filter.AssignableTypeFilter;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.hateoas.Resource;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* Converts domain objects from the DSpace service layer to rest objects, and from rest objects to resource
|
||||
* objects, applying {@link Projection}s where applicable.
|
||||
*/
|
||||
@Service
|
||||
public class ConverterService {
|
||||
|
||||
private static final Logger log = Logger.getLogger(ConverterService.class);
|
||||
|
||||
private final Map<String, Projection> projectionMap = new HashMap<>();
|
||||
|
||||
private final Map<Class, DSpaceConverter> converterMap = new HashMap<>();
|
||||
|
||||
private final Map<Class<? extends RestModel>, Constructor> resourceConstructors = new HashMap<>();
|
||||
|
||||
@Autowired
|
||||
private Utils utils;
|
||||
|
||||
@Autowired
|
||||
private HalLinkService halLinkService;
|
||||
|
||||
@Autowired
|
||||
private List<DSpaceConverter> converters;
|
||||
|
||||
@Autowired
|
||||
private List<Projection> projections;
|
||||
|
||||
/**
|
||||
* Converts the given model object to a rest object, using the appropriate {@link DSpaceConverter} and
|
||||
* the given projection.
|
||||
* <p>
|
||||
* The projection's {@link Projection#transformModel(Object)} method will be automatically applied
|
||||
* before conversion. If the rest object is a {@link RestModel}, the projection's
|
||||
* {@link Projection#transformRest(RestModel)} method will be automatically called after conversion.
|
||||
* </p>
|
||||
*
|
||||
* @param modelObject the model object, which may be a JPA entity any other class for which a converter exists.
|
||||
* @param projection the projection to use.
|
||||
* @param <M> the type of model object. A converter {@link Component} must exist that takes this as input.
|
||||
* @param <R> the inferred return type.
|
||||
* @return the converted object. If it's a {@link RestAddressableModel}, its
|
||||
* {@link RestAddressableModel#getProjection()} will be set to the given projection.
|
||||
* @throws IllegalArgumentException if there is no compatible converter.
|
||||
* @throws ClassCastException if the converter's return type is not compatible with the inferred return type.
|
||||
*/
|
||||
public <M, R> R toRest(M modelObject, Projection projection) {
|
||||
M transformedModel = projection.transformModel(modelObject);
|
||||
DSpaceConverter<M, R> converter = requireConverter(modelObject.getClass());
|
||||
R restObject = converter.convert(transformedModel, projection);
|
||||
if (restObject instanceof RestModel) {
|
||||
return (R) projection.transformRest((RestModel) restObject);
|
||||
}
|
||||
return restObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a list of model objects to a page of rest objects using the given {@link Projection}.
|
||||
*
|
||||
* @param modelObjects the list of model objects.
|
||||
* @param pageable the pageable.
|
||||
* @param total the total number of items.
|
||||
* @param projection the projection to use.
|
||||
* @param <M> the model object class.
|
||||
* @param <R> the rest object class.
|
||||
* @return the page.
|
||||
* @throws IllegalArgumentException if there is no compatible converter.
|
||||
* @throws ClassCastException if the converter's return type is not compatible with the inferred return type.
|
||||
*/
|
||||
public <M, R> Page<R> toRestPage(List<M> modelObjects, Pageable pageable, long total, Projection projection) {
|
||||
return new PageImpl<>(modelObjects, pageable, total).map((object) -> toRest(object, projection));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a list of model objects to a page of rest objects using the given {@link Projection}.
|
||||
*
|
||||
* @param modelObjects the page of model objects.
|
||||
* @param projection the projection to use.
|
||||
* @param <M> the model object class.
|
||||
* @param <R> the rest object class.
|
||||
* @return the page.
|
||||
* @throws IllegalArgumentException if there is no compatible converter.
|
||||
* @throws ClassCastException if the converter's return type is not compatible with the inferred return type.
|
||||
*/
|
||||
public <M, R> Page<R> toRestPage(Page<M> modelObjects, Projection projection) {
|
||||
return modelObjects.map((object) -> toRest(object, projection));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the converter supporting the given class as input.
|
||||
*
|
||||
* @param sourceClass the desired converter's input type.
|
||||
* @param <M> the converter's input type.
|
||||
* @param <R> the converter's output type.
|
||||
* @return the converter.
|
||||
* @throws IllegalArgumentException if there is no such converter.
|
||||
*/
|
||||
<M, R> DSpaceConverter<M, R> getConverter(Class<M> sourceClass) {
|
||||
return (DSpaceConverter<M, R>) requireConverter(sourceClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given rest object to a {@link HALResource} object.
|
||||
* <p>
|
||||
* If the rest object is a {@link RestAddressableModel}, the projection returned by
|
||||
* {@link RestAddressableModel#getProjection()} will be used to determine which optional
|
||||
* embeds and links will be added, and {@link Projection#transformResource(HALResource)}
|
||||
* will be automatically called before returning the final, fully converted resource.
|
||||
* </p><p>
|
||||
* In all cases, the {@link HalLinkService} will be used immediately after the resource is constructed,
|
||||
* to ensure all {@link HalLinkFactory}s have had a chance to add links as needed.
|
||||
* </p>
|
||||
*
|
||||
* @param restObject the input rest object.
|
||||
* @param <T> the return type, a subclass of {@link HALResource}.
|
||||
* @return the fully converted resource, with all automatic links and embeds applied.
|
||||
* @throws IllegalArgumentException if there is no compatible resource constructor.
|
||||
* @throws ClassCastException if the resource type is not compatible with the inferred return type.
|
||||
*/
|
||||
public <T extends HALResource> T toResource(RestModel restObject) {
|
||||
T halResource = getResource(restObject);
|
||||
if (restObject instanceof RestAddressableModel) {
|
||||
utils.embedOrLinkClassLevelRels(halResource);
|
||||
halLinkService.addLinks(halResource);
|
||||
Projection projection = ((RestAddressableModel) restObject).getProjection();
|
||||
return projection.transformResource(halResource);
|
||||
} else {
|
||||
halLinkService.addLinks(halResource);
|
||||
}
|
||||
return halResource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the projection with the given name, or the default (no-op) projection if null is given.
|
||||
*
|
||||
* @param projectionName the projection name, or {@code null}.
|
||||
* @return the projection with the given name, or {@link DefaultProjection} if {@code null} is given.
|
||||
* @throws IllegalArgumentException if a name is provided and such a projection cannot be found.
|
||||
*/
|
||||
public Projection getProjection(@Nullable String projectionName) {
|
||||
return projectionName == null ? Projection.DEFAULT : requireProjection(projectionName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns an instance of the appropriate {@link HALResource} subclass for the given rest object.
|
||||
* <p>
|
||||
* <b>Note:</b> Only two forms of constructor are supported for resources that can be created with this method:
|
||||
* A one-argument constructor taking the wrapped {@link RestModel}, and a two-argument constructor also taking
|
||||
* a {@link Utils} instance. If both are found in a candidate resource's constructor, the two-argument form
|
||||
* will be used.
|
||||
* </p>
|
||||
*
|
||||
* @param restObject the rest object to wrap.
|
||||
* @param <T> the return type, a subclass of {@link HALResource}.
|
||||
* @return a new resource instance of the appropriate type.
|
||||
*/
|
||||
private <T extends HALResource> T getResource(RestModel restObject) {
|
||||
Constructor constructor = resourceConstructors.get(restObject.getClass());
|
||||
if (constructor == null) {
|
||||
throw new IllegalArgumentException("No constructor found to get resource class from " + restObject);
|
||||
}
|
||||
try {
|
||||
if (constructor.getParameterCount() == 2) {
|
||||
return (T) constructor.newInstance(restObject, utils);
|
||||
} else {
|
||||
return (T) constructor.newInstance(restObject);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
if (e.getTargetException() instanceof RuntimeException) {
|
||||
throw (RuntimeException) e.getTargetException();
|
||||
}
|
||||
throw new RuntimeException(e);
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the projection with the given name or throws an {@link IllegalArgumentException}.
|
||||
*
|
||||
* @param projectionName the projection name.
|
||||
* @return the projection.
|
||||
* @throws IllegalArgumentException if not found.
|
||||
*/
|
||||
private Projection requireProjection(String projectionName) {
|
||||
if (!projectionMap.containsKey(projectionName)) {
|
||||
throw new IllegalArgumentException("No such projection: " + projectionName);
|
||||
}
|
||||
return projectionMap.get(projectionName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the converter that supports the given source/input class or throws an {@link IllegalArgumentException}.
|
||||
*
|
||||
* @param sourceClass the source/input class.
|
||||
* @return the converter.
|
||||
* @throws IllegalArgumentException if not found.
|
||||
*/
|
||||
private DSpaceConverter requireConverter(Class sourceClass) {
|
||||
if (converterMap.containsKey(sourceClass)) {
|
||||
return converterMap.get(sourceClass);
|
||||
}
|
||||
for (Class converterSourceClass : converterMap.keySet()) {
|
||||
if (converterSourceClass.isAssignableFrom(sourceClass)) {
|
||||
return converterMap.get(converterSourceClass);
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("No converter found to get rest class from " + sourceClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates maps of injected components and constructors to be used by this service's public methods.
|
||||
*/
|
||||
@PostConstruct
|
||||
private void initialize() {
|
||||
// put all available projections in a map keyed by name
|
||||
for (Projection projection : projections) {
|
||||
projectionMap.put(projection.getName(), projection);
|
||||
}
|
||||
projectionMap.put(Projection.DEFAULT.getName(), Projection.DEFAULT);
|
||||
|
||||
// put all available converters in a map keyed by model (input) class
|
||||
for (DSpaceConverter converter : converters) {
|
||||
converterMap.put(converter.getModelClass(), converter);
|
||||
}
|
||||
|
||||
// scan all resource classes and look for compatible rest classes (by naming convention),
|
||||
// creating a map of resource constructors keyed by rest class, for later use.
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.addIncludeFilter(new AssignableTypeFilter(Resource.class));
|
||||
Set<BeanDefinition> beanDefinitions = provider.findCandidateComponents(
|
||||
HALResource.class.getPackage().getName().replaceAll("\\.", "/"));
|
||||
for (BeanDefinition beanDefinition : beanDefinitions) {
|
||||
String resourceClassName = beanDefinition.getBeanClassName();
|
||||
String resourceClassSimpleName = resourceClassName.substring(resourceClassName.lastIndexOf(".") + 1);
|
||||
String restClassSimpleName = resourceClassSimpleName
|
||||
.replaceAll("ResourceWrapper$", "RestWrapper")
|
||||
.replaceAll("Resource$", "Rest");
|
||||
String restClassName = RestModel.class.getPackage().getName() + "." + restClassSimpleName;
|
||||
try {
|
||||
Class<? extends RestModel> restClass =
|
||||
(Class<? extends RestModel>) Class.forName(restClassName);
|
||||
Class<HALResource<? extends RestModel>> resourceClass =
|
||||
(Class<HALResource<? extends RestModel>>) Class.forName(resourceClassName);
|
||||
Constructor compatibleConstructor = null;
|
||||
for (Constructor constructor : resourceClass.getDeclaredConstructors()) {
|
||||
if (constructor.getParameterCount() == 2 && constructor.getParameterTypes()[1] == Utils.class) {
|
||||
compatibleConstructor = constructor;
|
||||
break; // found preferred constructor
|
||||
} else if (constructor.getParameterCount() == 1) {
|
||||
compatibleConstructor = constructor;
|
||||
}
|
||||
}
|
||||
if (compatibleConstructor != null) {
|
||||
resourceConstructors.put(restClass, compatibleConstructor);
|
||||
} else {
|
||||
log.warn("Skipping registration of resource class " + resourceClassName
|
||||
+ "; compatible constructor not found");
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
log.warn("Skipping registration of resource class " + resourceClassName
|
||||
+ "; rest class not found: " + restClassName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -7,15 +7,11 @@
|
||||
*/
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
|
||||
public interface DSpaceConverter<M, R> extends Converter<M, R> {
|
||||
@Override
|
||||
public default R convert(M source) {
|
||||
return fromModel(source);
|
||||
}
|
||||
public interface DSpaceConverter<M, R> {
|
||||
|
||||
public abstract R fromModel(M obj);
|
||||
R convert(M modelObject, Projection projection);
|
||||
|
||||
public abstract M toModel(R obj);
|
||||
Class<M> getModelClass();
|
||||
}
|
||||
|
@@ -7,6 +7,8 @@
|
||||
*/
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import org.dspace.app.rest.model.MetadataValueList;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -21,32 +23,22 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
public abstract class DSpaceObjectConverter<M extends DSpaceObject, R extends org.dspace.app.rest.model
|
||||
.DSpaceObjectRest> implements DSpaceConverter<M, R> {
|
||||
|
||||
@Autowired(required = true)
|
||||
private MetadataConverter metadataConverter;
|
||||
@Autowired
|
||||
ConverterService converter;
|
||||
|
||||
@Override
|
||||
public R fromModel(M obj) {
|
||||
public R convert(M obj, Projection projection) {
|
||||
R resource = newInstance();
|
||||
resource.setProjection(projection);
|
||||
resource.setHandle(obj.getHandle());
|
||||
if (obj.getID() != null) {
|
||||
resource.setUuid(obj.getID().toString());
|
||||
}
|
||||
resource.setName(obj.getName());
|
||||
resource.setMetadata(metadataConverter.convert(obj.getMetadata()));
|
||||
MetadataValueList metadataValues = new MetadataValueList(obj.getMetadata());
|
||||
resource.setMetadata(converter.toRest(metadataValues, projection));
|
||||
return resource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public M toModel(R obj) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean supportsModel(DSpaceObject object) {
|
||||
return object != null && object.getClass().equals(getModelClass());
|
||||
}
|
||||
|
||||
protected abstract R newInstance();
|
||||
|
||||
protected abstract Class<M> getModelClass();
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import org.dspace.app.rest.model.ParameterValueRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.scripts.DSpaceCommandLineParameter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -20,7 +21,7 @@ public class DSpaceRunnableParameterConverter
|
||||
implements DSpaceConverter<DSpaceCommandLineParameter, ParameterValueRest> {
|
||||
|
||||
@Override
|
||||
public ParameterValueRest fromModel(DSpaceCommandLineParameter dSpaceCommandLineParameter) {
|
||||
public ParameterValueRest convert(DSpaceCommandLineParameter dSpaceCommandLineParameter, Projection projection) {
|
||||
ParameterValueRest parameterValueRest = new ParameterValueRest();
|
||||
parameterValueRest.setName(dSpaceCommandLineParameter.getName());
|
||||
parameterValueRest.setValue(dSpaceCommandLineParameter.getValue());
|
||||
@@ -28,6 +29,10 @@ public class DSpaceRunnableParameterConverter
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<DSpaceCommandLineParameter> getModelClass() {
|
||||
return DSpaceCommandLineParameter.class;
|
||||
}
|
||||
|
||||
public DSpaceCommandLineParameter toModel(ParameterValueRest parameterValueRest) {
|
||||
return new DSpaceCommandLineParameter(parameterValueRest.getName(), parameterValueRest.getValue());
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.dspace.app.rest.model.SearchConfigurationRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.discovery.configuration.DiscoveryConfiguration;
|
||||
import org.dspace.discovery.configuration.DiscoverySearchFilter;
|
||||
import org.dspace.discovery.configuration.DiscoverySearchFilterFacet;
|
||||
@@ -24,9 +25,13 @@ import org.springframework.stereotype.Component;
|
||||
* to the convert method.
|
||||
*/
|
||||
@Component
|
||||
public class DiscoverConfigurationConverter {
|
||||
public SearchConfigurationRest convert(DiscoveryConfiguration configuration) {
|
||||
public class DiscoverConfigurationConverter
|
||||
implements DSpaceConverter<DiscoveryConfiguration, SearchConfigurationRest> {
|
||||
|
||||
@Override
|
||||
public SearchConfigurationRest convert(DiscoveryConfiguration configuration, Projection projection) {
|
||||
SearchConfigurationRest searchConfigurationRest = new SearchConfigurationRest();
|
||||
searchConfigurationRest.setProjection(projection);
|
||||
if (configuration != null) {
|
||||
addSearchFilters(searchConfigurationRest,
|
||||
configuration.getSearchFilters(), configuration.getSidebarFacets());
|
||||
@@ -36,6 +41,11 @@ public class DiscoverConfigurationConverter {
|
||||
return searchConfigurationRest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<DiscoveryConfiguration> getModelClass() {
|
||||
return DiscoveryConfiguration.class;
|
||||
}
|
||||
|
||||
private void setDefaultSortOption(DiscoveryConfiguration configuration,
|
||||
SearchConfigurationRest searchConfigurationRest) {
|
||||
String defaultSort = configuration.getSearchSortConfiguration().SCORE;
|
||||
|
@@ -15,6 +15,7 @@ import org.dspace.app.rest.model.SearchFacetEntryRest;
|
||||
import org.dspace.app.rest.model.SearchFacetValueRest;
|
||||
import org.dspace.app.rest.model.SearchResultsRest;
|
||||
import org.dspace.app.rest.parameter.SearchFilter;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.discovery.DiscoverResult;
|
||||
import org.dspace.discovery.configuration.DiscoveryConfiguration;
|
||||
@@ -36,19 +37,20 @@ public class DiscoverFacetResultsConverter {
|
||||
|
||||
public FacetResultsRest convert(Context context, String facetName, String prefix, String query, String dsoType,
|
||||
String dsoScope, List<SearchFilter> searchFilters, DiscoverResult searchResult,
|
||||
DiscoveryConfiguration configuration, Pageable page) {
|
||||
DiscoveryConfiguration configuration, Pageable page, Projection projection) {
|
||||
FacetResultsRest facetResultsRest = new FacetResultsRest();
|
||||
facetResultsRest.setProjection(projection);
|
||||
|
||||
setRequestInformation(context, facetName, prefix, query, dsoType, dsoScope, searchFilters, searchResult,
|
||||
configuration, facetResultsRest, page);
|
||||
configuration, facetResultsRest, page, projection);
|
||||
|
||||
addToFacetResultList(facetName, searchResult, facetResultsRest, configuration, page);
|
||||
addToFacetResultList(facetName, searchResult, facetResultsRest, configuration, page, projection);
|
||||
|
||||
return facetResultsRest;
|
||||
}
|
||||
|
||||
private void addToFacetResultList(String facetName, DiscoverResult searchResult, FacetResultsRest facetResultsRest,
|
||||
DiscoveryConfiguration configuration, Pageable page) {
|
||||
DiscoveryConfiguration configuration, Pageable page, Projection projection) {
|
||||
|
||||
DiscoverySearchFilterFacet field = configuration.getSidebarFacet(facetName);
|
||||
List<DiscoverResult.FacetResult> facetValues = searchResult.getFacetResult(field);
|
||||
@@ -59,26 +61,27 @@ public class DiscoverFacetResultsConverter {
|
||||
//We requested one facet value more as the page size. We must make sure to not return the extra value.
|
||||
break;
|
||||
}
|
||||
SearchFacetValueRest searchFacetValueRest = buildSearchFacetValueRestFromFacetResult(value);
|
||||
SearchFacetValueRest searchFacetValueRest = buildSearchFacetValueRestFromFacetResult(value, projection);
|
||||
facetResultsRest.addToFacetResultList(searchFacetValueRest);
|
||||
valueCount++;
|
||||
}
|
||||
}
|
||||
|
||||
private SearchFacetValueRest buildSearchFacetValueRestFromFacetResult(DiscoverResult.FacetResult value) {
|
||||
return facetValueConverter.convert(value);
|
||||
private SearchFacetValueRest buildSearchFacetValueRestFromFacetResult(DiscoverResult.FacetResult value,
|
||||
Projection projection) {
|
||||
return facetValueConverter.convert(value, projection);
|
||||
}
|
||||
|
||||
private void setRequestInformation(Context context, String facetName, String prefix, String query, String dsoType,
|
||||
String dsoScope, List<SearchFilter> searchFilters, DiscoverResult searchResult,
|
||||
DiscoveryConfiguration configuration, FacetResultsRest facetResultsRest,
|
||||
Pageable page) {
|
||||
Pageable page, Projection projection) {
|
||||
facetResultsRest.setQuery(query);
|
||||
facetResultsRest.setPrefix(prefix);
|
||||
facetResultsRest.setScope(dsoScope);
|
||||
facetResultsRest.setDsoType(dsoType);
|
||||
|
||||
facetResultsRest.setFacetEntry(convertFacetEntry(facetName, searchResult, configuration, page));
|
||||
facetResultsRest.setFacetEntry(convertFacetEntry(facetName, searchResult, configuration, page, projection));
|
||||
|
||||
facetResultsRest.setSort(SearchResultsRest.Sorting.fromPage(page));
|
||||
|
||||
@@ -91,10 +94,12 @@ public class DiscoverFacetResultsConverter {
|
||||
}
|
||||
|
||||
private SearchFacetEntryRest convertFacetEntry(final String facetName, final DiscoverResult searchResult,
|
||||
final DiscoveryConfiguration configuration, final Pageable page) {
|
||||
final DiscoveryConfiguration configuration, final Pageable page,
|
||||
final Projection projection) {
|
||||
DiscoverySearchFilterFacet field = configuration.getSidebarFacet(facetName);
|
||||
|
||||
SearchFacetEntryRest facetEntryRest = new SearchFacetEntryRest(facetName);
|
||||
facetEntryRest.setProjection(projection);
|
||||
List<DiscoverResult.FacetResult> facetResults = searchResult.getFacetResult(field);
|
||||
|
||||
if (!facetResults.isEmpty()) {
|
||||
|
@@ -8,6 +8,7 @@
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import org.dspace.app.rest.model.SearchFacetValueRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.discovery.DiscoverResult;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -17,8 +18,9 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class DiscoverFacetValueConverter {
|
||||
|
||||
public SearchFacetValueRest convert(final DiscoverResult.FacetResult value) {
|
||||
public SearchFacetValueRest convert(final DiscoverResult.FacetResult value, final Projection projection) {
|
||||
SearchFacetValueRest valueRest = new SearchFacetValueRest();
|
||||
valueRest.setProjection(projection);
|
||||
valueRest.setLabel(value.getDisplayedValue());
|
||||
valueRest.setFilterValue(value.getAsFilterQuery());
|
||||
valueRest.setFilterType(value.getFilterType());
|
||||
|
@@ -16,6 +16,7 @@ import org.dspace.app.rest.model.SearchFacetEntryRest;
|
||||
import org.dspace.app.rest.model.SearchFacetValueRest;
|
||||
import org.dspace.app.rest.model.SearchResultsRest;
|
||||
import org.dspace.app.rest.parameter.SearchFilter;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.discovery.DiscoverQuery;
|
||||
import org.dspace.discovery.DiscoverResult;
|
||||
@@ -39,13 +40,15 @@ public class DiscoverFacetsConverter {
|
||||
|
||||
public SearchResultsRest convert(Context context, String query, String dsoType, String configurationName,
|
||||
String dsoScope, List<SearchFilter> searchFilters, final Pageable page,
|
||||
DiscoveryConfiguration configuration, DiscoverResult searchResult) {
|
||||
DiscoveryConfiguration configuration, DiscoverResult searchResult,
|
||||
Projection projection) {
|
||||
|
||||
SearchResultsRest searchResultsRest = new SearchResultsRest();
|
||||
searchResultsRest.setProjection(projection);
|
||||
|
||||
setRequestInformation(context, query, dsoType, configurationName, dsoScope, searchFilters, page,
|
||||
searchResultsRest);
|
||||
addFacetValues(context, searchResult, searchResultsRest, configuration);
|
||||
addFacetValues(context, searchResult, searchResultsRest, configuration, projection);
|
||||
|
||||
return searchResultsRest;
|
||||
}
|
||||
@@ -64,13 +67,14 @@ public class DiscoverFacetsConverter {
|
||||
* The DiscoveryConfiguration applied to the query
|
||||
*/
|
||||
public void addFacetValues(Context context, final DiscoverResult searchResult, final SearchResultsRest resultsRest,
|
||||
final DiscoveryConfiguration configuration) {
|
||||
final DiscoveryConfiguration configuration, final Projection projection) {
|
||||
|
||||
List<DiscoverySearchFilterFacet> facets = configuration.getSidebarFacets();
|
||||
for (DiscoverySearchFilterFacet field : CollectionUtils.emptyIfNull(facets)) {
|
||||
List<DiscoverResult.FacetResult> facetValues = searchResult.getFacetResult(field);
|
||||
|
||||
SearchFacetEntryRest facetEntry = new SearchFacetEntryRest(field.getIndexFieldName());
|
||||
facetEntry.setProjection(projection);
|
||||
int valueCount = 0;
|
||||
facetEntry.setHasMore(false);
|
||||
facetEntry.setFacetLimit(field.getFacetLimit());
|
||||
@@ -84,7 +88,7 @@ public class DiscoverFacetsConverter {
|
||||
// are
|
||||
// more results available.
|
||||
if (valueCount < field.getFacetLimit()) {
|
||||
SearchFacetValueRest valueRest = facetValueConverter.convert(value);
|
||||
SearchFacetValueRest valueRest = facetValueConverter.convert(value, projection);
|
||||
|
||||
facetEntry.addValue(valueRest);
|
||||
} else {
|
||||
|
@@ -18,6 +18,7 @@ import org.dspace.app.rest.model.RestAddressableModel;
|
||||
import org.dspace.app.rest.model.SearchResultEntryRest;
|
||||
import org.dspace.app.rest.model.SearchResultsRest;
|
||||
import org.dspace.app.rest.parameter.SearchFilter;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.discovery.DiscoverResult;
|
||||
import org.dspace.discovery.IndexableObject;
|
||||
@@ -45,15 +46,17 @@ public class DiscoverResultConverter {
|
||||
public SearchResultsRest convert(final Context context, final String query, final String dsoType,
|
||||
final String configurationName, final String scope,
|
||||
final List<SearchFilter> searchFilters, final Pageable page,
|
||||
final DiscoverResult searchResult, final DiscoveryConfiguration configuration) {
|
||||
final DiscoverResult searchResult, final DiscoveryConfiguration configuration,
|
||||
final Projection projection) {
|
||||
|
||||
SearchResultsRest resultsRest = new SearchResultsRest();
|
||||
resultsRest.setProjection(projection);
|
||||
|
||||
setRequestInformation(context, query, dsoType, configurationName, scope, searchFilters, page, resultsRest);
|
||||
|
||||
addSearchResults(searchResult, resultsRest);
|
||||
addSearchResults(searchResult, resultsRest, projection);
|
||||
|
||||
addFacetValues(context, searchResult, resultsRest, configuration);
|
||||
addFacetValues(context, searchResult, resultsRest, configuration, projection);
|
||||
|
||||
resultsRest.setTotalNumberOfResults(searchResult.getTotalSearchResults());
|
||||
|
||||
@@ -61,16 +64,18 @@ public class DiscoverResultConverter {
|
||||
}
|
||||
|
||||
private void addFacetValues(Context context, final DiscoverResult searchResult, final SearchResultsRest resultsRest,
|
||||
final DiscoveryConfiguration configuration) {
|
||||
facetConverter.addFacetValues(context, searchResult, resultsRest, configuration);
|
||||
final DiscoveryConfiguration configuration, final Projection projection) {
|
||||
facetConverter.addFacetValues(context, searchResult, resultsRest, configuration, projection);
|
||||
}
|
||||
|
||||
private void addSearchResults(final DiscoverResult searchResult, final SearchResultsRest resultsRest) {
|
||||
private void addSearchResults(final DiscoverResult searchResult, final SearchResultsRest resultsRest,
|
||||
final Projection projection) {
|
||||
for (IndexableObject dspaceObject : CollectionUtils.emptyIfNull(searchResult.getIndexableObjects())) {
|
||||
SearchResultEntryRest resultEntry = new SearchResultEntryRest();
|
||||
resultEntry.setProjection(projection);
|
||||
|
||||
//Convert the DSpace Object to its REST model
|
||||
resultEntry.setIndexableObject(convertDSpaceObject(dspaceObject));
|
||||
resultEntry.setIndexableObject(convertDSpaceObject(dspaceObject, projection));
|
||||
|
||||
//Add hit highlighting for this DSO if present
|
||||
DiscoverResult.IndexableObjectHighlightResult highlightedResults = searchResult
|
||||
@@ -86,10 +91,10 @@ public class DiscoverResultConverter {
|
||||
}
|
||||
}
|
||||
|
||||
private RestAddressableModel convertDSpaceObject(final IndexableObject dspaceObject) {
|
||||
private RestAddressableModel convertDSpaceObject(final IndexableObject dspaceObject, final Projection projection) {
|
||||
for (IndexableObjectConverter<IndexableObject, RestAddressableModel> converter : converters) {
|
||||
if (converter.supportsModel(dspaceObject)) {
|
||||
return converter.convert(dspaceObject);
|
||||
return converter.convert(dspaceObject, projection);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@@ -14,6 +14,7 @@ import java.util.List;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.app.rest.model.EPersonRest;
|
||||
import org.dspace.app.rest.model.GroupRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.eperson.EPerson;
|
||||
import org.dspace.eperson.Group;
|
||||
@@ -30,17 +31,17 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class EPersonConverter extends DSpaceObjectConverter<EPerson, org.dspace.app.rest.model.EPersonRest> {
|
||||
|
||||
@Autowired(required = true)
|
||||
private GroupConverter epersonGroupConverter;
|
||||
@Autowired
|
||||
private ConverterService converter;
|
||||
|
||||
@Autowired(required = true)
|
||||
@Autowired
|
||||
private GroupService groupService;
|
||||
|
||||
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(EPersonConverter.class);
|
||||
|
||||
@Override
|
||||
public EPersonRest fromModel(EPerson obj) {
|
||||
EPersonRest eperson = super.fromModel(obj);
|
||||
public EPersonRest convert(EPerson obj, Projection projection) {
|
||||
EPersonRest eperson = super.convert(obj, projection);
|
||||
eperson.setLastActive(obj.getLastActive());
|
||||
eperson.setNetid(obj.getNetid());
|
||||
eperson.setCanLogIn(obj.canLogIn());
|
||||
@@ -51,31 +52,26 @@ public class EPersonConverter extends DSpaceObjectConverter<EPerson, org.dspace.
|
||||
return eperson;
|
||||
}
|
||||
|
||||
public EPersonRest fromModelWithGroups(Context context, EPerson ePerson) throws SQLException {
|
||||
EPersonRest eperson = fromModel(ePerson);
|
||||
public EPersonRest fromModelWithGroups(Context context, EPerson ePerson, Projection projection)
|
||||
throws SQLException {
|
||||
EPersonRest eperson = convert(ePerson, projection);
|
||||
|
||||
List<GroupRest> groups = new ArrayList<GroupRest>();
|
||||
List<GroupRest> groups = new ArrayList<>();
|
||||
for (Group g : groupService.allMemberGroups(context, ePerson)) {
|
||||
groups.add(epersonGroupConverter.convert(g));
|
||||
groups.add(converter.toRest(g, projection));
|
||||
}
|
||||
|
||||
eperson.setGroups(groups);
|
||||
return eperson;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EPerson toModel(EPersonRest obj) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EPersonRest newInstance() {
|
||||
return new EPersonRest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<EPerson> getModelClass() {
|
||||
public Class<EPerson> getModelClass() {
|
||||
return EPerson.class;
|
||||
}
|
||||
|
||||
|
@@ -8,6 +8,7 @@
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import org.dspace.app.rest.model.EntityTypeRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.content.EntityType;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -18,29 +19,17 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class EntityTypeConverter implements DSpaceConverter<org.dspace.content.EntityType, EntityTypeRest> {
|
||||
|
||||
/**
|
||||
* This method converts the EntityType model object that is passed along in the params to the
|
||||
* REST representation of this object
|
||||
* @param obj The EntityType model object to be converted
|
||||
* @return The EntityType REST object that is made from the model object
|
||||
*/
|
||||
public EntityTypeRest fromModel(EntityType obj) {
|
||||
@Override
|
||||
public EntityTypeRest convert(EntityType obj, Projection projection) {
|
||||
EntityTypeRest entityTypeRest = new EntityTypeRest();
|
||||
entityTypeRest.setProjection(projection);
|
||||
entityTypeRest.setId(obj.getID());
|
||||
entityTypeRest.setLabel(obj.getLabel());
|
||||
return entityTypeRest;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method converts the EntityType REST object that is passed along in the params to the model
|
||||
* representation of this object
|
||||
* @param obj The EntityType REST object to be converted
|
||||
* @return The EntityType model object that is made from the REST object
|
||||
*/
|
||||
public EntityType toModel(EntityTypeRest obj) {
|
||||
EntityType entityType = new EntityType();
|
||||
entityType.setId(obj.getId());
|
||||
entityType.setLabel(obj.getLabel());
|
||||
return entityType;
|
||||
@Override
|
||||
public Class<EntityType> getModelClass() {
|
||||
return EntityType.class;
|
||||
}
|
||||
}
|
||||
|
@@ -1,61 +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.converter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.rest.model.DSpaceObjectRest;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* This is the converter from/to an unknown DSpaceObject in the DSpace API data model and the
|
||||
* REST data model
|
||||
*
|
||||
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||
*/
|
||||
@Component
|
||||
public class GenericDSpaceObjectConverter
|
||||
extends DSpaceObjectConverter<org.dspace.content.DSpaceObject, org.dspace.app.rest.model.DSpaceObjectRest> {
|
||||
|
||||
@Autowired
|
||||
private List<DSpaceObjectConverter> converters;
|
||||
|
||||
private static final Logger log = Logger.getLogger(GenericDSpaceObjectConverter.class);
|
||||
|
||||
/**
|
||||
* Convert a DSpaceObject in its REST representation using a suitable converter
|
||||
*/
|
||||
@Override
|
||||
public DSpaceObjectRest fromModel(org.dspace.content.DSpaceObject dspaceObject) {
|
||||
for (DSpaceObjectConverter converter : converters) {
|
||||
if (converter.supportsModel(dspaceObject)) {
|
||||
return converter.fromModel(dspaceObject);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.dspace.content.DSpaceObject toModel(DSpaceObjectRest obj) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DSpaceObjectRest newInstance() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<DSpaceObject> getModelClass() {
|
||||
return DSpaceObject.class;
|
||||
}
|
||||
|
||||
}
|
@@ -12,6 +12,7 @@ import java.util.List;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.app.rest.model.GroupRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.eperson.Group;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -27,31 +28,25 @@ public class GroupConverter extends DSpaceObjectConverter<Group, org.dspace.app.
|
||||
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(GroupConverter.class);
|
||||
|
||||
@Override
|
||||
public GroupRest fromModel(Group obj) {
|
||||
GroupRest epersongroup = super.fromModel(obj);
|
||||
public GroupRest convert(Group obj, Projection projection) {
|
||||
GroupRest epersongroup = super.convert(obj, projection);
|
||||
epersongroup.setPermanent(obj.isPermanent());
|
||||
List<GroupRest> groups = new ArrayList<GroupRest>();
|
||||
for (Group g : obj.getMemberGroups()) {
|
||||
groups.add(convert(g));
|
||||
groups.add(convert(g, projection));
|
||||
}
|
||||
epersongroup.setGroups(groups);
|
||||
|
||||
return epersongroup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group toModel(GroupRest obj) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GroupRest newInstance() {
|
||||
return new GroupRest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<Group> getModelClass() {
|
||||
public Class<Group> getModelClass() {
|
||||
return Group.class;
|
||||
}
|
||||
|
||||
|
@@ -14,11 +14,11 @@ import org.dspace.app.rest.model.HarvestStatusEnum;
|
||||
import org.dspace.app.rest.model.HarvestTypeEnum;
|
||||
import org.dspace.app.rest.model.HarvestedCollectionRest;
|
||||
import org.dspace.app.rest.model.HarvesterMetadataRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.harvest.HarvestedCollection;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
/**
|
||||
* This is the converter from/to the HarvestedCollection in the DSpace API data model and the REST data model
|
||||
@@ -29,18 +29,19 @@ import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
public class HarvestedCollectionConverter implements DSpaceConverter<HarvestedCollection, HarvestedCollectionRest> {
|
||||
|
||||
@Autowired
|
||||
private CollectionConverter collectionConverter;
|
||||
private ConverterService converter;
|
||||
|
||||
@Override
|
||||
public HarvestedCollectionRest fromModel(HarvestedCollection obj) {
|
||||
public HarvestedCollectionRest convert(HarvestedCollection obj, Projection projection) {
|
||||
HarvestedCollectionRest harvestedCollectionRest = new HarvestedCollectionRest();
|
||||
harvestedCollectionRest.setProjection(projection);
|
||||
|
||||
if (obj != null) {
|
||||
HarvestTypeEnum harvestTypeEnum = HarvestTypeEnum.fromInt(obj.getHarvestType());
|
||||
HarvestStatusEnum harvestStatusEnum = HarvestStatusEnum.fromInt(obj.getHarvestStatus());
|
||||
|
||||
harvestedCollectionRest.setId(obj.getID());
|
||||
harvestedCollectionRest.setCollection(collectionConverter.fromModel(obj.getCollection()));
|
||||
harvestedCollectionRest.setCollection(converter.toRest(obj.getCollection(), projection));
|
||||
harvestedCollectionRest.setHarvestType(harvestTypeEnum);
|
||||
harvestedCollectionRest.setHarvestStatus(harvestStatusEnum);
|
||||
harvestedCollectionRest.setMetadataConfigId(obj.getHarvestMetadataConfig());
|
||||
@@ -59,24 +60,25 @@ public class HarvestedCollectionConverter implements DSpaceConverter<HarvestedCo
|
||||
|
||||
public HarvestedCollectionRest fromModel(HarvestedCollection obj,
|
||||
Collection collection,
|
||||
List<Map<String,String>> metadata_configs) {
|
||||
HarvestedCollectionRest harvestedCollectionRest = this.fromModel(obj);
|
||||
List<Map<String,String>> metadata_configs,
|
||||
Projection projection) {
|
||||
HarvestedCollectionRest harvestedCollectionRest = this.convert(obj, projection);
|
||||
|
||||
// Add collectionRest to the empty HarvestedCollectionRest so that we can use its uuid later in the linkFactory
|
||||
if (obj == null) {
|
||||
harvestedCollectionRest.setCollection(collectionConverter.fromModel(collection));
|
||||
harvestedCollectionRest.setCollection(converter.toRest(collection, projection));
|
||||
}
|
||||
|
||||
HarvesterMetadataRest harvesterMetadataRest = new HarvesterMetadataRest();
|
||||
harvesterMetadataRest.setProjection(projection);
|
||||
harvesterMetadataRest.setConfigs(metadata_configs);
|
||||
|
||||
harvestedCollectionRest.setMetadataConfigs(harvesterMetadataRest);
|
||||
|
||||
return harvestedCollectionRest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HarvestedCollection toModel(HarvestedCollectionRest obj) {
|
||||
throw new NotImplementedException();
|
||||
public Class<HarvestedCollection> getModelClass() {
|
||||
return HarvestedCollection.class;
|
||||
}
|
||||
}
|
||||
|
@@ -26,6 +26,5 @@ public interface IndexableObjectConverter<M extends IndexableObject,
|
||||
* the IndexableObject to check
|
||||
* @return true if the actual converter implementation is able to manage the supplied IndexableObject
|
||||
*/
|
||||
public boolean supportsModel(IndexableObject idxo);
|
||||
|
||||
}
|
||||
boolean supportsModel(IndexableObject idxo);
|
||||
}
|
||||
|
@@ -7,26 +7,19 @@
|
||||
*/
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.app.rest.model.BundleRest;
|
||||
import org.dspace.app.rest.model.ItemRest;
|
||||
import org.dspace.app.rest.model.RelationshipRest;
|
||||
import org.dspace.app.rest.utils.ContextUtil;
|
||||
import org.dspace.app.rest.model.MetadataValueList;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.MetadataValue;
|
||||
import org.dspace.content.Relationship;
|
||||
import org.dspace.content.service.ItemService;
|
||||
import org.dspace.content.service.RelationshipService;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.discovery.IndexableObject;
|
||||
import org.dspace.services.RequestService;
|
||||
import org.dspace.services.model.Request;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -38,98 +31,52 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component
|
||||
public class ItemConverter
|
||||
extends DSpaceObjectConverter<org.dspace.content.Item, org.dspace.app.rest.model.ItemRest>
|
||||
extends DSpaceObjectConverter<Item, ItemRest>
|
||||
implements IndexableObjectConverter<Item, ItemRest> {
|
||||
|
||||
@Autowired(required = true)
|
||||
private CollectionConverter collectionConverter;
|
||||
@Autowired(required = true)
|
||||
private BundleConverter bundleConverter;
|
||||
@Autowired
|
||||
private RequestService requestService;
|
||||
@Autowired
|
||||
private RelationshipService relationshipService;
|
||||
@Autowired
|
||||
private RelationshipConverter relationshipConverter;
|
||||
private ConverterService converter;
|
||||
|
||||
@Autowired
|
||||
private ItemService itemService;
|
||||
@Autowired
|
||||
private MetadataConverter metadataConverter;
|
||||
|
||||
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(ItemConverter.class);
|
||||
|
||||
@Override
|
||||
public ItemRest fromModel(org.dspace.content.Item obj) {
|
||||
ItemRest item = super.fromModel(obj);
|
||||
public ItemRest convert(Item obj, Projection projection) {
|
||||
ItemRest item = super.convert(obj, projection);
|
||||
item.setInArchive(obj.isArchived());
|
||||
item.setDiscoverable(obj.isDiscoverable());
|
||||
item.setWithdrawn(obj.isWithdrawn());
|
||||
item.setLastModified(obj.getLastModified());
|
||||
try {
|
||||
Collection c = obj.getOwningCollection();
|
||||
if (c != null) {
|
||||
item.setOwningCollection(collectionConverter.fromModel(c));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Error setting owning collection for item" + item.getHandle(), e);
|
||||
Collection owningCollection = obj.getOwningCollection();
|
||||
if (owningCollection != null) {
|
||||
item.setOwningCollection(converter.toRest(owningCollection, projection));
|
||||
}
|
||||
try {
|
||||
Collection c = obj.getTemplateItemOf();
|
||||
if (c != null) {
|
||||
item.setTemplateItemOf(collectionConverter.fromModel(c));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Error setting template item of for item " + item.getHandle(), e);
|
||||
Collection templateItemOf = obj.getTemplateItemOf();
|
||||
if (templateItemOf != null) {
|
||||
item.setTemplateItemOf(converter.toRest(templateItemOf, projection));
|
||||
}
|
||||
|
||||
item.setBundles(obj.getBundles()
|
||||
.stream()
|
||||
.map(x -> bundleConverter.fromModel(x))
|
||||
.map(x -> (BundleRest) converter.toRest(x, projection))
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
List<Relationship> relationships = new LinkedList<>();
|
||||
try {
|
||||
Context context;
|
||||
Request currentRequest = requestService.getCurrentRequest();
|
||||
if (currentRequest != null) {
|
||||
HttpServletRequest request = currentRequest.getHttpServletRequest();
|
||||
context = ContextUtil.obtainContext(request);
|
||||
} else {
|
||||
context = new Context();
|
||||
}
|
||||
relationships = relationshipService.findByItem(context, obj);
|
||||
} catch (SQLException e) {
|
||||
log.error("Error retrieving relationships for item " + item.getHandle(), e);
|
||||
}
|
||||
List<RelationshipRest> relationshipRestList = new LinkedList<>();
|
||||
for (Relationship relationship : relationships) {
|
||||
RelationshipRest relationshipRest = relationshipConverter.fromModel(relationship);
|
||||
relationshipRestList.add(relationshipRest);
|
||||
}
|
||||
item.setRelationships(relationshipRestList);
|
||||
|
||||
List<MetadataValue> fullList = new LinkedList<>();
|
||||
fullList = itemService.getMetadata(obj, Item.ANY, Item.ANY, Item.ANY, Item.ANY, true);
|
||||
|
||||
item.setMetadata(metadataConverter.convert(fullList));
|
||||
|
||||
List<MetadataValue> fullList = itemService.getMetadata(obj, Item.ANY, Item.ANY, Item.ANY, Item.ANY, true);
|
||||
MetadataValueList metadataValues = new MetadataValueList(fullList);
|
||||
item.setMetadata(converter.toRest(metadataValues, projection));
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.dspace.content.Item toModel(ItemRest obj) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemRest newInstance() {
|
||||
return new ItemRest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<Item> getModelClass() {
|
||||
public Class<Item> getModelClass() {
|
||||
return Item.class;
|
||||
}
|
||||
|
||||
|
@@ -17,7 +17,9 @@ import java.util.TreeSet;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.dspace.app.rest.model.MetadataRest;
|
||||
import org.dspace.app.rest.model.MetadataValueList;
|
||||
import org.dspace.app.rest.model.MetadataValueRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.content.Item;
|
||||
@@ -26,39 +28,33 @@ import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.service.DSpaceObjectService;
|
||||
import org.dspace.core.Context;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Converter to translate between lists of domain {@link MetadataValue}s and {@link MetadataRest} representations.
|
||||
*/
|
||||
@Component
|
||||
public class MetadataConverter implements Converter<List<MetadataValue>, MetadataRest> {
|
||||
public class MetadataConverter implements DSpaceConverter<MetadataValueList, MetadataRest> {
|
||||
|
||||
@Autowired
|
||||
private ContentServiceFactory contentServiceFactory;
|
||||
|
||||
@Autowired
|
||||
private MetadataValueConverter valueConverter;
|
||||
private ConverterService converter;
|
||||
|
||||
/**
|
||||
* Gets a rest representation of the given list of domain metadata values.
|
||||
*
|
||||
* @param metadataValueList the domain values.
|
||||
* @return the rest representation.
|
||||
*/
|
||||
@Override
|
||||
public MetadataRest convert(List<MetadataValue> metadataValueList) {
|
||||
public MetadataRest convert(MetadataValueList metadataValues,
|
||||
Projection projection) {
|
||||
// Convert each value to a DTO while retaining place order in a map of key -> SortedSet
|
||||
Map<String, SortedSet<MetadataValueRest>> mapOfSortedSets = new HashMap<>();
|
||||
for (MetadataValue metadataValue : metadataValueList) {
|
||||
for (MetadataValue metadataValue : metadataValues) {
|
||||
String key = metadataValue.getMetadataField().toString('.');
|
||||
SortedSet<MetadataValueRest> set = mapOfSortedSets.get(key);
|
||||
if (set == null) {
|
||||
set = new TreeSet<>(Comparator.comparingInt(MetadataValueRest::getPlace));
|
||||
mapOfSortedSets.put(key, set);
|
||||
}
|
||||
set.add(valueConverter.convert(metadataValue));
|
||||
set.add(converter.toRest(metadataValue, projection));
|
||||
}
|
||||
|
||||
MetadataRest metadataRest = new MetadataRest();
|
||||
@@ -72,6 +68,11 @@ public class MetadataConverter implements Converter<List<MetadataValue>, Metadat
|
||||
return metadataRest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<MetadataValueList> getModelClass() {
|
||||
return MetadataValueList.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a DSpace object's domain metadata values from a rest representation.
|
||||
*
|
||||
|
@@ -8,6 +8,8 @@
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import org.dspace.app.rest.model.MetadataFieldRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.content.MetadataField;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -18,24 +20,24 @@ import org.springframework.stereotype.Component;
|
||||
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||
*/
|
||||
@Component
|
||||
public class MetadataFieldConverter implements DSpaceConverter<org.dspace.content.MetadataField, MetadataFieldRest> {
|
||||
@Autowired(required = true)
|
||||
private MetadataSchemaConverter metadataSchemaConverter;
|
||||
public class MetadataFieldConverter implements DSpaceConverter<MetadataField, MetadataFieldRest> {
|
||||
@Autowired
|
||||
private ConverterService converter;
|
||||
|
||||
@Override
|
||||
public MetadataFieldRest fromModel(org.dspace.content.MetadataField obj) {
|
||||
public MetadataFieldRest convert(MetadataField obj, Projection projection) {
|
||||
MetadataFieldRest field = new MetadataFieldRest();
|
||||
field.setProjection(projection);
|
||||
field.setId(obj.getID());
|
||||
field.setElement(obj.getElement());
|
||||
field.setQualifier(obj.getQualifier());
|
||||
field.setScopeNote(obj.getScopeNote());
|
||||
field.setSchema(metadataSchemaConverter.convert(obj.getMetadataSchema()));
|
||||
field.setSchema(converter.toRest(obj.getMetadataSchema(), projection));
|
||||
return field;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.dspace.content.MetadataField toModel(MetadataFieldRest obj) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
public Class<MetadataField> getModelClass() {
|
||||
return MetadataField.class;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -8,6 +8,8 @@
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import org.dspace.app.rest.model.MetadataSchemaRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.content.MetadataSchema;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
@@ -17,10 +19,11 @@ import org.springframework.stereotype.Component;
|
||||
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||
*/
|
||||
@Component
|
||||
public class MetadataSchemaConverter implements DSpaceConverter<org.dspace.content.MetadataSchema, MetadataSchemaRest> {
|
||||
public class MetadataSchemaConverter implements DSpaceConverter<MetadataSchema, MetadataSchemaRest> {
|
||||
@Override
|
||||
public MetadataSchemaRest fromModel(org.dspace.content.MetadataSchema obj) {
|
||||
public MetadataSchemaRest convert(MetadataSchema obj, Projection projection) {
|
||||
MetadataSchemaRest schema = new MetadataSchemaRest();
|
||||
schema.setProjection(projection);
|
||||
schema.setId(obj.getID());
|
||||
schema.setNamespace(obj.getNamespace());
|
||||
schema.setPrefix(obj.getName());
|
||||
@@ -28,8 +31,7 @@ public class MetadataSchemaConverter implements DSpaceConverter<org.dspace.conte
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.dspace.content.MetadataSchema toModel(MetadataSchemaRest obj) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
public Class<MetadataSchema> getModelClass() {
|
||||
return MetadataSchema.class;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -8,24 +8,18 @@
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import org.dspace.app.rest.model.MetadataValueRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.content.MetadataValue;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Converter to translate between domain {@link MetadataValue}s and {@link MetadataValueRest} representations.
|
||||
*/
|
||||
@Component
|
||||
public class MetadataValueConverter implements Converter<MetadataValue, MetadataValueRest> {
|
||||
public class MetadataValueConverter implements DSpaceConverter<MetadataValue, MetadataValueRest> {
|
||||
|
||||
/**
|
||||
* Gets a rest representation of the given domain metadata value.
|
||||
*
|
||||
* @param metadataValue the domain value.
|
||||
* @return the rest representation.
|
||||
*/
|
||||
@Override
|
||||
public MetadataValueRest convert(MetadataValue metadataValue) {
|
||||
public MetadataValueRest convert(MetadataValue metadataValue, Projection projection) {
|
||||
MetadataValueRest metadataValueRest = new MetadataValueRest();
|
||||
metadataValueRest.setValue(metadataValue.getValue());
|
||||
metadataValueRest.setLanguage(metadataValue.getLanguage());
|
||||
@@ -34,4 +28,9 @@ public class MetadataValueConverter implements Converter<MetadataValue, Metadata
|
||||
metadataValueRest.setPlace(metadataValue.getPlace());
|
||||
return metadataValueRest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<MetadataValue> getModelClass() {
|
||||
return MetadataValue.class;
|
||||
}
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import org.dspace.app.rest.model.PoolTaskRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.discovery.IndexableObject;
|
||||
import org.dspace.xmlworkflow.storedcomponents.PoolTask;
|
||||
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
|
||||
@@ -25,26 +26,21 @@ public class PoolTaskConverter
|
||||
implements IndexableObjectConverter<PoolTask, org.dspace.app.rest.model.PoolTaskRest> {
|
||||
|
||||
@Autowired
|
||||
private WorkflowItemConverter workflowItemConverter;
|
||||
|
||||
@Autowired
|
||||
private EPersonConverter epersonConverter;
|
||||
|
||||
@Autowired
|
||||
private GroupConverter groupConverter;
|
||||
private ConverterService converter;
|
||||
|
||||
@Override
|
||||
public PoolTaskRest fromModel(PoolTask obj) {
|
||||
public PoolTaskRest convert(PoolTask obj, Projection projection) {
|
||||
PoolTaskRest taskRest = new PoolTaskRest();
|
||||
taskRest.setProjection(projection);
|
||||
|
||||
XmlWorkflowItem witem = obj.getWorkflowItem();
|
||||
taskRest.setId(obj.getID());
|
||||
taskRest.setWorkflowitem(workflowItemConverter.convert(witem));
|
||||
taskRest.setWorkflowitem(converter.toRest(witem, projection));
|
||||
if (obj.getEperson() != null) {
|
||||
taskRest.setEperson(epersonConverter.convert(obj.getEperson()));
|
||||
taskRest.setEperson(converter.toRest(obj.getEperson(), projection));
|
||||
}
|
||||
if (obj.getGroup() != null) {
|
||||
taskRest.setGroup(groupConverter.convert(obj.getGroup()));
|
||||
taskRest.setGroup(converter.toRest(obj.getGroup(), projection));
|
||||
}
|
||||
taskRest.setAction(obj.getActionID());
|
||||
taskRest.setStep(obj.getStepID());
|
||||
@@ -52,8 +48,8 @@ public class PoolTaskConverter
|
||||
}
|
||||
|
||||
@Override
|
||||
public PoolTask toModel(PoolTaskRest obj) {
|
||||
return null;
|
||||
public Class<PoolTask> getModelClass() {
|
||||
return PoolTask.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,4 +57,4 @@ public class PoolTaskConverter
|
||||
return object instanceof PoolTask;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -5,13 +5,13 @@
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.app.rest.converter.processes;
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.dspace.app.rest.converter.DSpaceConverter;
|
||||
import org.dspace.app.rest.converter.DSpaceRunnableParameterConverter;
|
||||
import org.dspace.app.rest.model.ParameterValueRest;
|
||||
import org.dspace.app.rest.model.ProcessRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.scripts.Process;
|
||||
import org.dspace.scripts.service.ProcessService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -24,14 +24,15 @@ import org.springframework.stereotype.Component;
|
||||
public class ProcessConverter implements DSpaceConverter<Process, ProcessRest> {
|
||||
|
||||
@Autowired
|
||||
private ProcessService processService;
|
||||
private ConverterService converter;
|
||||
|
||||
@Autowired
|
||||
private DSpaceRunnableParameterConverter dSpaceRunnableParameterConverter;
|
||||
private ProcessService processService;
|
||||
|
||||
@Override
|
||||
public ProcessRest fromModel(Process process) {
|
||||
public ProcessRest convert(Process process, Projection projection) {
|
||||
ProcessRest processRest = new ProcessRest();
|
||||
processRest.setProjection(projection);
|
||||
processRest.setId(process.getID());
|
||||
processRest.setScriptName(process.getName());
|
||||
processRest.setProcessId(process.getID());
|
||||
@@ -39,14 +40,13 @@ public class ProcessConverter implements DSpaceConverter<Process, ProcessRest> {
|
||||
processRest.setProcessStatus(process.getProcessStatus());
|
||||
processRest.setStartTime(process.getStartTime());
|
||||
processRest.setEndTime(process.getFinishedTime());
|
||||
processRest.setParameterRestList(
|
||||
processService.getParameters(process).stream().map(x -> dSpaceRunnableParameterConverter.fromModel(x))
|
||||
.collect(Collectors.toList()));
|
||||
processRest.setParameterRestList(processService.getParameters(process).stream()
|
||||
.map(x -> (ParameterValueRest) converter.toRest(x, projection)).collect(Collectors.toList()));
|
||||
return processRest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Process toModel(ProcessRest obj) {
|
||||
return null;
|
||||
public Class<Process> getModelClass() {
|
||||
return Process.class;
|
||||
}
|
||||
}
|
@@ -8,10 +8,10 @@
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import org.dspace.app.rest.model.RelationshipRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.content.Relationship;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
/**
|
||||
* This converter is responsible for transforming the model representation of an Relationship to the REST
|
||||
@@ -21,20 +21,15 @@ import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
public class RelationshipConverter implements DSpaceConverter<Relationship, RelationshipRest> {
|
||||
|
||||
@Autowired
|
||||
private RelationshipTypeConverter relationshipTypeConverter;
|
||||
private ConverterService converter;
|
||||
|
||||
|
||||
/**
|
||||
* This method converts the Relationship model object that is passed along in the params to the
|
||||
* REST representation of this object
|
||||
* @param obj The Relationship model object to be converted
|
||||
* @return The Relationship REST object that is made from the model object
|
||||
*/
|
||||
public RelationshipRest fromModel(Relationship obj) {
|
||||
@Override
|
||||
public RelationshipRest convert(Relationship obj, Projection projection) {
|
||||
RelationshipRest relationshipRest = new RelationshipRest();
|
||||
relationshipRest.setProjection(projection);
|
||||
relationshipRest.setId(obj.getID());
|
||||
relationshipRest.setLeftId(obj.getLeftItem().getID());
|
||||
relationshipRest.setRelationshipType(relationshipTypeConverter.fromModel(obj.getRelationshipType()));
|
||||
relationshipRest.setRelationshipType(converter.toRest(obj.getRelationshipType(), projection));
|
||||
relationshipRest.setRightId(obj.getRightItem().getID());
|
||||
relationshipRest.setLeftPlace(obj.getLeftPlace());
|
||||
relationshipRest.setRightPlace(obj.getRightPlace());
|
||||
@@ -43,13 +38,8 @@ public class RelationshipConverter implements DSpaceConverter<Relationship, Rela
|
||||
return relationshipRest;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method converts the Relationship REST object that is passed along in the params to the model
|
||||
* representation of this object
|
||||
* @param obj The Relationship REST object to be converted
|
||||
* @return The Relationship model object that is made from the REST object
|
||||
*/
|
||||
public Relationship toModel(RelationshipRest obj) {
|
||||
throw new NotImplementedException();
|
||||
@Override
|
||||
public Class<Relationship> getModelClass() {
|
||||
return Relationship.class;
|
||||
}
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import org.dspace.app.rest.model.RelationshipTypeRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.content.RelationshipType;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -20,16 +21,12 @@ import org.springframework.stereotype.Component;
|
||||
public class RelationshipTypeConverter implements DSpaceConverter<RelationshipType, RelationshipTypeRest> {
|
||||
|
||||
@Autowired
|
||||
private EntityTypeConverter entityTypeConverter;
|
||||
private ConverterService converter;
|
||||
|
||||
/**
|
||||
* This method converts the RelationshipType model object that is passed along in the params to the
|
||||
* REST representation of this object
|
||||
* @param obj The RelationshipType model object to be converted
|
||||
* @return The RelationshipType REST object that is made from the model object
|
||||
*/
|
||||
public RelationshipTypeRest fromModel(RelationshipType obj) {
|
||||
@Override
|
||||
public RelationshipTypeRest convert(RelationshipType obj, Projection projection) {
|
||||
RelationshipTypeRest relationshipTypeRest = new RelationshipTypeRest();
|
||||
relationshipTypeRest.setProjection(projection);
|
||||
|
||||
relationshipTypeRest.setId(obj.getID());
|
||||
relationshipTypeRest.setLeftwardType(obj.getLeftwardType());
|
||||
@@ -38,20 +35,14 @@ public class RelationshipTypeConverter implements DSpaceConverter<RelationshipTy
|
||||
relationshipTypeRest.setLeftMaxCardinality(obj.getLeftMaxCardinality());
|
||||
relationshipTypeRest.setRightMinCardinality(obj.getRightMinCardinality());
|
||||
relationshipTypeRest.setRightMaxCardinality(obj.getRightMaxCardinality());
|
||||
relationshipTypeRest.setLeftType(entityTypeConverter.fromModel(obj.getLeftType()));
|
||||
relationshipTypeRest.setRightType(entityTypeConverter.fromModel(obj.getRightType()));
|
||||
relationshipTypeRest.setLeftType(converter.toRest(obj.getLeftType(), projection));
|
||||
relationshipTypeRest.setRightType(converter.toRest(obj.getRightType(), projection));
|
||||
|
||||
return relationshipTypeRest;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method converts the RelationshipType REST object that is passed along in the params to the model
|
||||
* representation of this object
|
||||
* @param obj The RelationshipType REST object to be converted
|
||||
* @return The RelationshipType model object that is made from the REST object
|
||||
*/
|
||||
public RelationshipType toModel(RelationshipTypeRest obj) {
|
||||
|
||||
return null;
|
||||
@Override
|
||||
public Class<RelationshipType> getModelClass() {
|
||||
return RelationshipType.class;
|
||||
}
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import org.dspace.app.rest.model.ResourcePolicyRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.authorize.ResourcePolicy;
|
||||
import org.dspace.authorize.service.ResourcePolicyService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -26,9 +27,10 @@ public class ResourcePolicyConverter implements DSpaceConverter<ResourcePolicy,
|
||||
ResourcePolicyService resourcePolicyService;
|
||||
|
||||
@Override
|
||||
public ResourcePolicyRest fromModel(ResourcePolicy obj) {
|
||||
public ResourcePolicyRest convert(ResourcePolicy obj, Projection projection) {
|
||||
|
||||
ResourcePolicyRest model = new ResourcePolicyRest();
|
||||
model.setProjection(projection);
|
||||
|
||||
model.setId(obj.getID());
|
||||
|
||||
@@ -52,9 +54,8 @@ public class ResourcePolicyConverter implements DSpaceConverter<ResourcePolicy,
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourcePolicy toModel(ResourcePolicyRest obj) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
public Class<ResourcePolicy> getModelClass() {
|
||||
return ResourcePolicy.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -7,10 +7,15 @@
|
||||
*/
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import org.dspace.app.rest.converter.processes.ParameterConverter;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.cli.Option;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.dspace.app.rest.model.ParameterRest;
|
||||
import org.dspace.app.rest.model.ScriptRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.scripts.DSpaceRunnable;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
@@ -20,21 +25,29 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class ScriptConverter implements DSpaceConverter<DSpaceRunnable, ScriptRest> {
|
||||
|
||||
@Autowired
|
||||
private ParameterConverter parameterConverter;
|
||||
|
||||
@Override
|
||||
public ScriptRest fromModel(DSpaceRunnable script) {
|
||||
public ScriptRest convert(DSpaceRunnable script, Projection projection) {
|
||||
ScriptRest scriptRest = new ScriptRest();
|
||||
scriptRest.setProjection(projection);
|
||||
scriptRest.setDescription(script.getDescription());
|
||||
scriptRest.setId(script.getName());
|
||||
scriptRest.setName(script.getName());
|
||||
scriptRest.setParameterRestList(parameterConverter.convertOptionsToParameterRestList(script.getOptions()));
|
||||
|
||||
List<ParameterRest> parameterRestList = new LinkedList<>();
|
||||
for (Option option : CollectionUtils.emptyIfNull(script.getOptions().getOptions())) {
|
||||
ParameterRest parameterRest = new ParameterRest();
|
||||
parameterRest.setDescription(option.getDescription());
|
||||
parameterRest.setName((option.getOpt() != null ? "-" + option.getOpt() : "--" + option.getLongOpt()));
|
||||
parameterRest.setType(((Class) option.getType()).getSimpleName());
|
||||
parameterRestList.add(parameterRest);
|
||||
}
|
||||
scriptRest.setParameterRestList(parameterRestList);
|
||||
|
||||
return scriptRest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DSpaceRunnable toModel(ScriptRest obj) {
|
||||
return null;
|
||||
public Class<DSpaceRunnable> getModelClass() {
|
||||
return DSpaceRunnable.class;
|
||||
}
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import org.dspace.app.rest.model.SiteRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.content.Site;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -18,16 +19,11 @@ import org.springframework.stereotype.Component;
|
||||
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||
*/
|
||||
@Component
|
||||
public class SiteConverter
|
||||
extends DSpaceObjectConverter<org.dspace.content.Site, org.dspace.app.rest.model.SiteRest> {
|
||||
@Override
|
||||
public org.dspace.content.Site toModel(org.dspace.app.rest.model.SiteRest obj) {
|
||||
return (org.dspace.content.Site) super.toModel(obj);
|
||||
}
|
||||
public class SiteConverter extends DSpaceObjectConverter<Site, SiteRest> {
|
||||
|
||||
@Override
|
||||
public SiteRest fromModel(org.dspace.content.Site obj) {
|
||||
return (SiteRest) super.fromModel(obj);
|
||||
public SiteRest convert(Site obj, Projection projection) {
|
||||
return super.convert(obj, projection);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -36,7 +32,7 @@ public class SiteConverter
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<Site> getModelClass() {
|
||||
public Class<Site> getModelClass() {
|
||||
return Site.class;
|
||||
}
|
||||
}
|
||||
|
@@ -13,11 +13,11 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.lang3.NotImplementedException;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.app.rest.model.CollectionRest;
|
||||
import org.dspace.app.rest.model.SubmissionDefinitionRest;
|
||||
import org.dspace.app.rest.model.SubmissionSectionRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.app.rest.utils.ContextUtil;
|
||||
import org.dspace.app.util.SubmissionConfig;
|
||||
import org.dspace.app.util.SubmissionConfigReaderException;
|
||||
@@ -47,17 +47,18 @@ public class SubmissionDefinitionConverter implements DSpaceConverter<Submission
|
||||
private RequestService requestService;
|
||||
|
||||
@Autowired
|
||||
private CollectionConverter collectionConverter;
|
||||
private ConverterService converter;
|
||||
|
||||
@Override
|
||||
public SubmissionDefinitionRest fromModel(SubmissionConfig obj) {
|
||||
public SubmissionDefinitionRest convert(SubmissionConfig obj, Projection projection) {
|
||||
SubmissionDefinitionRest sd = new SubmissionDefinitionRest();
|
||||
sd.setProjection(projection);
|
||||
sd.setName(obj.getSubmissionName());
|
||||
sd.setDefaultConf(obj.isDefaultConf());
|
||||
List<SubmissionSectionRest> panels = new LinkedList<SubmissionSectionRest>();
|
||||
for (int idx = 0; idx < obj.getNumberOfSteps(); idx++) {
|
||||
SubmissionStepConfig step = obj.getStep(idx);
|
||||
SubmissionSectionRest sp = panelConverter.convert(step);
|
||||
SubmissionSectionRest sp = converter.toRest(step, projection);
|
||||
panels.add(sp);
|
||||
}
|
||||
|
||||
@@ -68,8 +69,9 @@ public class SubmissionDefinitionConverter implements DSpaceConverter<Submission
|
||||
List<Collection> collections = panelConverter.getSubmissionConfigReader()
|
||||
.getCollectionsBySubmissionConfig(context,
|
||||
obj.getSubmissionName());
|
||||
List<CollectionRest> collectionsRest = collections.stream().map(
|
||||
(collection) -> collectionConverter.convert(collection)).collect(Collectors.toList());
|
||||
DSpaceConverter<Collection, CollectionRest> cc = converter.getConverter(Collection.class);
|
||||
List<CollectionRest> collectionsRest = collections.stream().map((collection) ->
|
||||
cc.convert(collection, projection)).collect(Collectors.toList());
|
||||
sd.setCollections(collectionsRest);
|
||||
} catch (SQLException | IllegalStateException | SubmissionConfigReaderException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
@@ -79,7 +81,7 @@ public class SubmissionDefinitionConverter implements DSpaceConverter<Submission
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubmissionConfig toModel(SubmissionDefinitionRest obj) {
|
||||
throw new NotImplementedException("Method not implemented");
|
||||
public Class<SubmissionConfig> getModelClass() {
|
||||
return SubmissionConfig.class;
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,6 @@ import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.NotImplementedException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dspace.app.rest.model.ScopeEnum;
|
||||
import org.dspace.app.rest.model.SubmissionFormFieldRest;
|
||||
@@ -22,6 +21,7 @@ import org.dspace.app.rest.model.SubmissionVisibilityRest;
|
||||
import org.dspace.app.rest.model.VisibilityEnum;
|
||||
import org.dspace.app.rest.model.submit.SelectableMetadata;
|
||||
import org.dspace.app.rest.model.submit.SelectableRelationship;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.app.rest.repository.SubmissionFormRestRepository;
|
||||
import org.dspace.app.rest.utils.AuthorityUtils;
|
||||
import org.dspace.app.util.DCInput;
|
||||
@@ -51,8 +51,9 @@ public class SubmissionFormConverter implements DSpaceConverter<DCInputSet, Subm
|
||||
private SubmissionFormRestRepository submissionFormRestRepository;
|
||||
|
||||
@Override
|
||||
public SubmissionFormRest fromModel(DCInputSet obj) {
|
||||
public SubmissionFormRest convert(DCInputSet obj, Projection projection) {
|
||||
SubmissionFormRest sd = new SubmissionFormRest();
|
||||
sd.setProjection(projection);
|
||||
sd.setName(obj.getFormName());
|
||||
DCInput[][] step = obj.getFields();
|
||||
List<SubmissionFormRowRest> rows = getPage(step, obj.getFormName());
|
||||
@@ -203,7 +204,7 @@ public class SubmissionFormConverter implements DSpaceConverter<DCInputSet, Subm
|
||||
}
|
||||
|
||||
@Override
|
||||
public DCInputSet toModel(SubmissionFormRest obj) {
|
||||
throw new NotImplementedException("Method not implemented");
|
||||
public Class<DCInputSet> getModelClass() {
|
||||
return DCInputSet.class;
|
||||
}
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@ import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.app.rest.model.SubmissionSectionRest;
|
||||
import org.dspace.app.rest.model.SubmissionVisibilityRest;
|
||||
import org.dspace.app.rest.model.VisibilityEnum;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.app.util.SubmissionConfigReader;
|
||||
import org.dspace.app.util.SubmissionConfigReaderException;
|
||||
import org.dspace.app.util.SubmissionStepConfig;
|
||||
@@ -30,8 +31,9 @@ public class SubmissionSectionConverter implements DSpaceConverter<SubmissionSte
|
||||
private SubmissionConfigReader submissionConfigReader;
|
||||
|
||||
@Override
|
||||
public SubmissionSectionRest fromModel(SubmissionStepConfig step) {
|
||||
public SubmissionSectionRest convert(SubmissionStepConfig step, Projection projection) {
|
||||
SubmissionSectionRest sp = new SubmissionSectionRest();
|
||||
sp.setProjection(projection);
|
||||
sp.setMandatory(step.isMandatory());
|
||||
sp.setHeader(step.getHeading());
|
||||
sp.setSectionType(step.getType());
|
||||
@@ -41,7 +43,6 @@ public class SubmissionSectionConverter implements DSpaceConverter<SubmissionSte
|
||||
return sp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubmissionStepConfig toModel(SubmissionSectionRest obj) {
|
||||
SubmissionStepConfig step;
|
||||
|
||||
@@ -53,10 +54,15 @@ public class SubmissionSectionConverter implements DSpaceConverter<SubmissionSte
|
||||
return step;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<SubmissionStepConfig> getModelClass() {
|
||||
return SubmissionStepConfig.class;
|
||||
}
|
||||
|
||||
public SubmissionConfigReader getSubmissionConfigReader() throws SubmissionConfigReaderException {
|
||||
if (submissionConfigReader == null) {
|
||||
submissionConfigReader = new SubmissionConfigReader();
|
||||
}
|
||||
return submissionConfigReader;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import org.dspace.app.rest.model.WorkflowItemRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.app.util.SubmissionConfigReaderException;
|
||||
import org.dspace.discovery.IndexableObject;
|
||||
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
|
||||
@@ -29,15 +30,16 @@ public class WorkflowItemConverter
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorkflowItemRest fromModel(XmlWorkflowItem obj) {
|
||||
public WorkflowItemRest convert(XmlWorkflowItem obj, Projection projection) {
|
||||
WorkflowItemRest witem = new WorkflowItemRest();
|
||||
fillFromModel(obj, witem);
|
||||
witem.setProjection(projection);
|
||||
fillFromModel(obj, witem, projection);
|
||||
return witem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlWorkflowItem toModel(WorkflowItemRest obj) {
|
||||
return null;
|
||||
public Class<XmlWorkflowItem> getModelClass() {
|
||||
return XmlWorkflowItem.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -8,6 +8,7 @@
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import org.dspace.app.rest.model.WorkspaceItemRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.app.util.SubmissionConfigReaderException;
|
||||
import org.dspace.content.WorkspaceItem;
|
||||
import org.dspace.discovery.IndexableObject;
|
||||
@@ -28,18 +29,22 @@ public class WorkspaceItemConverter
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorkspaceItemRest fromModel(org.dspace.content.WorkspaceItem obj) {
|
||||
public WorkspaceItemRest convert(org.dspace.content.WorkspaceItem obj, Projection projection) {
|
||||
WorkspaceItemRest witem = new WorkspaceItemRest();
|
||||
|
||||
fillFromModel(obj, witem);
|
||||
witem.setProjection(projection);
|
||||
fillFromModel(obj, witem, projection);
|
||||
return witem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.dspace.content.WorkspaceItem toModel(WorkspaceItemRest obj) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<WorkspaceItem> getModelClass() {
|
||||
return WorkspaceItem.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsModel(IndexableObject object) {
|
||||
return object instanceof WorkspaceItem;
|
||||
|
@@ -1,43 +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.converter.processes;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.cli.Option;
|
||||
import org.apache.commons.cli.Options;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.dspace.app.rest.model.ParameterRest;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* This converter will convert the Options of a script to a list of ParameterRest objects
|
||||
*/
|
||||
@Component
|
||||
public class ParameterConverter {
|
||||
|
||||
/**
|
||||
* This method will convert the Options of a script to a list of ParameterRest objects
|
||||
* @param options The options of a script
|
||||
* @return The resulting list of ParameterRest objects
|
||||
*/
|
||||
public List<ParameterRest> convertOptionsToParameterRestList(Options options) {
|
||||
List<ParameterRest> listToReturn = new LinkedList<>();
|
||||
|
||||
for (Option option : CollectionUtils.emptyIfNull(options.getOptions())) {
|
||||
ParameterRest parameterRest = new ParameterRest();
|
||||
parameterRest.setDescription(option.getDescription());
|
||||
parameterRest.setName((option.getOpt() != null ? "-" + option.getOpt() : "--" + option.getLongOpt()));
|
||||
parameterRest.setType(((Class) option.getType()).getSimpleName());
|
||||
listToReturn.add(parameterRest);
|
||||
}
|
||||
|
||||
return listToReturn;
|
||||
}
|
||||
}
|
@@ -41,14 +41,14 @@ public class AuthorityEntryHalLinkFactory extends HalLinkFactory<AuthorityEntryR
|
||||
.findRel(null, null, AuthorityRest.CATEGORY,
|
||||
English.plural(AuthorityRest.NAME),
|
||||
entry.getAuthorityName() + "/" + AuthorityRest.ENTRY,
|
||||
entry.getOtherInformation().get(AuthorityUtils.RESERVED_KEYMAP_PARENT), null, null,
|
||||
null)).toUriComponentsBuilder();
|
||||
entry.getOtherInformation().get(AuthorityUtils.RESERVED_KEYMAP_PARENT), null, null))
|
||||
.toUriComponentsBuilder();
|
||||
|
||||
list.add(buildLink(AuthorityUtils.RESERVED_KEYMAP_PARENT, uriComponentsBuilder.build().toString()));
|
||||
}
|
||||
}
|
||||
String selfLinkString = linkTo(
|
||||
getMethodOn().findOne(entry.getCategory(), English.plural(entry.getType()), entry.getAuthorityName(), null))
|
||||
getMethodOn().findOne(entry.getCategory(), English.plural(entry.getType()), entry.getAuthorityName()))
|
||||
.toUriComponentsBuilder().build().toString() + "/entryValues/" + entry.getId();
|
||||
list.add(buildLink(Link.REL_SELF, selfLinkString));
|
||||
}
|
||||
|
@@ -37,7 +37,7 @@ public class BrowseEntryHalLinkFactory extends HalLinkFactory<BrowseEntryResourc
|
||||
UriComponentsBuilder baseLink = uriBuilder(
|
||||
getMethodOn(bix.getCategory(), bix.getType()).findRel(null, null, bix.getCategory(),
|
||||
English.plural(bix.getType()), bix.getId(),
|
||||
BrowseIndexRest.ITEMS, null, null, null));
|
||||
BrowseIndexRest.ITEMS, null, null));
|
||||
|
||||
addFilterParams(baseLink, data);
|
||||
|
||||
|
@@ -21,7 +21,6 @@ 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.core.annotation.AnnotationUtils;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -46,26 +45,33 @@ public class DSpaceResourceHalLinkFactory extends HalLinkFactory<DSpaceResource,
|
||||
Method readMethod = pd.getReadMethod();
|
||||
String name = pd.getName();
|
||||
if (readMethod != null && !"class".equals(name)) {
|
||||
LinkRest linkAnnotation = AnnotationUtils.findAnnotation(readMethod, LinkRest.class);
|
||||
LinkRest linkRest = utils.findLinkAnnotation(readMethod);
|
||||
|
||||
if (linkAnnotation != null) {
|
||||
if (StringUtils.isNotBlank(linkAnnotation.name())) {
|
||||
name = linkAnnotation.name();
|
||||
if (linkRest != null) {
|
||||
if (StringUtils.isNotBlank(linkRest.name())) {
|
||||
name = linkRest.name();
|
||||
}
|
||||
|
||||
Link linkToSubResource = utils.linkToSubResource(data, name);
|
||||
// no method is specified to retrieve the linked object(s) so check if it is already here
|
||||
if (StringUtils.isBlank(linkAnnotation.method())) {
|
||||
if (StringUtils.isBlank(linkRest.method())) {
|
||||
Object linkedObject = readMethod.invoke(data);
|
||||
|
||||
if (linkedObject instanceof RestAddressableModel
|
||||
&& linkAnnotation.linkClass().isAssignableFrom(linkedObject.getClass())) {
|
||||
&& linkRest.linkClass().isAssignableFrom(linkedObject.getClass())) {
|
||||
|
||||
linkToSubResource = utils
|
||||
.linkToSingleResource((RestAddressableModel) linkedObject, name);
|
||||
}
|
||||
|
||||
if (linkedObject != null || !linkAnnotation.optional()) {
|
||||
if (linkedObject != null || !linkRest.linkOptional() || !linkRest.embedOptional()) {
|
||||
|
||||
if (linkRest.linkOptional() && linkRest.embedOptional()
|
||||
&& !halResource.getContent().getProjection()
|
||||
.allowOptionalLink(halResource, linkRest)) {
|
||||
continue; // projection disallows this optional method-level link
|
||||
}
|
||||
|
||||
halResource.add(linkToSubResource);
|
||||
}
|
||||
}
|
||||
|
@@ -39,7 +39,7 @@ public class SubmissionSectionHalLinkFactory extends HalLinkFactory<SubmissionSe
|
||||
UriComponentsBuilder uriComponentsBuilder = linkTo(
|
||||
getMethodOn(SubmissionFormRest.CATEGORY, SubmissionFormRest.NAME)
|
||||
.findRel(null, null, SubmissionFormRest.CATEGORY, English.plural(SubmissionFormRest.NAME),
|
||||
sd.getId(), "", null, null, null))
|
||||
sd.getId(), "", null, null))
|
||||
.toUriComponentsBuilder();
|
||||
String uribuilder = uriComponentsBuilder.build().toString();
|
||||
list.add(
|
||||
@@ -49,7 +49,7 @@ public class SubmissionSectionHalLinkFactory extends HalLinkFactory<SubmissionSe
|
||||
UriComponentsBuilder uriComponentsBuilder = linkTo(
|
||||
getMethodOn(RestResourceController.class, SubmissionUploadRest.CATEGORY, SubmissionUploadRest.NAME)
|
||||
.findRel(null, null, SubmissionUploadRest.CATEGORY, English.plural(SubmissionUploadRest.NAME),
|
||||
sd.getId(), "", null, null, null))
|
||||
sd.getId(), "", null, null))
|
||||
.toUriComponentsBuilder();
|
||||
String uribuilder = uriComponentsBuilder.build().toString();
|
||||
list.add(
|
||||
|
@@ -27,7 +27,8 @@ import org.springframework.stereotype.Component;
|
||||
public class EntityTypeHalLinkFactory extends HalLinkFactory<EntityTypeResource, RelationshipTypeRestController> {
|
||||
@Override
|
||||
protected void addLinks(EntityTypeResource halResource, Pageable pageable, LinkedList<Link> list) throws Exception {
|
||||
list.add(buildLink("relationshiptypes", getMethodOn().retrieve(halResource.getContent().getId(), null, null)));
|
||||
list.add(buildLink("relationshiptypes", getMethodOn().retrieve(
|
||||
halResource.getContent().getId(), null, null)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -29,10 +29,10 @@ public class RelationshipHalLinkFactory extends HalLinkFactory<RelationshipResou
|
||||
throws Exception {
|
||||
|
||||
list.add(buildLink("leftItem", getMethodOn()
|
||||
.findOne(ItemRest.CATEGORY, English.plural(ItemRest.NAME), halResource.getContent().getLeftId(), null)));
|
||||
.findOne(ItemRest.CATEGORY, English.plural(ItemRest.NAME), halResource.getContent().getLeftId())));
|
||||
|
||||
list.add(buildLink("rightItem", getMethodOn()
|
||||
.findOne(ItemRest.CATEGORY, English.plural(ItemRest.NAME), halResource.getContent().getRightId(), null)));
|
||||
.findOne(ItemRest.CATEGORY, English.plural(ItemRest.NAME), halResource.getContent().getRightId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -35,10 +35,6 @@ public abstract class AInprogressSubmissionRest<T extends Serializable> extends
|
||||
@JsonIgnore
|
||||
private EPersonRest submitter;
|
||||
|
||||
public AInprogressSubmissionRest() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Date getLastModified() {
|
||||
return lastModified;
|
||||
}
|
||||
@@ -90,4 +86,4 @@ public abstract class AInprogressSubmissionRest<T extends Serializable> extends
|
||||
this.collection = collection;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -56,7 +56,7 @@ public class AuthenticationStatusRest extends BaseObjectRest<Integer> {
|
||||
}
|
||||
}
|
||||
|
||||
@LinkRest(linkClass = EPersonRest.class, name = "eperson", optional = true)
|
||||
@LinkRest(linkClass = EPersonRest.class, name = "eperson", linkOptional = true)
|
||||
@JsonIgnore
|
||||
public EPersonRest getEPersonRest() {
|
||||
return ePersonRest;
|
||||
@@ -81,4 +81,4 @@ public class AuthenticationStatusRest extends BaseObjectRest<Integer> {
|
||||
public void setOkay(boolean okay) {
|
||||
this.okay = okay;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ import org.dspace.app.rest.RestResourceController;
|
||||
*
|
||||
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||
*/
|
||||
public class AuthorityEntryRest implements RestAddressableModel {
|
||||
public class AuthorityEntryRest extends RestAddressableModel {
|
||||
public static final String NAME = "authorityEntry";
|
||||
private String id;
|
||||
private String display;
|
||||
|
@@ -15,8 +15,19 @@ import org.dspace.app.rest.RestResourceController;
|
||||
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||
*/
|
||||
@LinksRest(links = {
|
||||
@LinkRest(name = AuthorityRest.ENTRIES, linkClass = AuthorityEntryRest.class, method = "query", optional = true),
|
||||
@LinkRest(name = AuthorityRest.ENTRY, linkClass = AuthorityEntryRest.class, method = "getResource", optional = true)
|
||||
@LinkRest(name = AuthorityRest.ENTRIES,
|
||||
linkClass = AuthorityEntryRest.class,
|
||||
method = "query",
|
||||
embedOptional = true,
|
||||
linkOptional = true
|
||||
),
|
||||
@LinkRest(
|
||||
name = AuthorityRest.ENTRY,
|
||||
linkClass = AuthorityEntryRest.class,
|
||||
method = "getResource",
|
||||
embedOptional = true,
|
||||
linkOptional = true
|
||||
)
|
||||
})
|
||||
public class AuthorityRest extends BaseObjectRest<String> {
|
||||
|
||||
|
@@ -21,7 +21,7 @@ import org.springframework.hateoas.Identifiable;
|
||||
* @param <T> the class of the resource identifier
|
||||
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||
*/
|
||||
public abstract class BaseObjectRest<T extends Serializable> implements Identifiable<T>, RestAddressableModel {
|
||||
public abstract class BaseObjectRest<T extends Serializable> extends RestAddressableModel implements Identifiable<T> {
|
||||
|
||||
protected T id;
|
||||
|
||||
|
@@ -101,4 +101,4 @@ public class BitstreamFormatRest extends BaseObjectRest<Integer> {
|
||||
public Class getController() {
|
||||
return RestResourceController.class;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -19,9 +19,19 @@ import org.dspace.app.rest.RestResourceController;
|
||||
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||
*/
|
||||
@LinksRest(links = {
|
||||
@LinkRest(name = BrowseIndexRest.ITEMS, linkClass = ItemRest.class, method = "listBrowseItems"),
|
||||
@LinkRest(name = BrowseIndexRest.ENTRIES, linkClass = BrowseEntryRest.class, method = "listBrowseEntries",
|
||||
optional = true)
|
||||
@LinkRest(
|
||||
name = BrowseIndexRest.ITEMS,
|
||||
linkClass = ItemRest.class,
|
||||
method = "listBrowseItems",
|
||||
embedOptional = true
|
||||
),
|
||||
@LinkRest(
|
||||
name = BrowseIndexRest.ENTRIES,
|
||||
linkClass = BrowseEntryRest.class,
|
||||
method = "listBrowseEntries",
|
||||
embedOptional = true,
|
||||
linkOptional = true
|
||||
)
|
||||
})
|
||||
public class BrowseIndexRest extends BaseObjectRest<String> {
|
||||
private static final long serialVersionUID = -4870333170249999559L;
|
||||
|
@@ -92,4 +92,4 @@ public class ClaimedTaskRest extends BaseObjectRest<Integer> {
|
||||
public void setWorkflowitem(WorkflowItemRest workflowitem) {
|
||||
this.workflowitem = workflowitem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -18,8 +18,13 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||
*/
|
||||
@LinksRest(links = {
|
||||
@LinkRest(name = CollectionRest.LICENSE, linkClass = LicenseRest.class, method = "getLicenseCollection", optional
|
||||
= true)
|
||||
@LinkRest(
|
||||
name = CollectionRest.LICENSE,
|
||||
linkClass = LicenseRest.class,
|
||||
method = "getLicenseCollection",
|
||||
embedOptional = true,
|
||||
linkOptional = true
|
||||
)
|
||||
})
|
||||
public class CollectionRest extends DSpaceObjectRest {
|
||||
public static final String NAME = "collection";
|
||||
|
@@ -11,7 +11,6 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import org.dspace.app.rest.DiscoveryRestController;
|
||||
import org.dspace.app.rest.parameter.SearchFilter;
|
||||
|
||||
|
@@ -123,4 +123,4 @@ public class EPersonRest extends DSpaceObjectRest {
|
||||
return RestResourceController.class;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -156,7 +156,7 @@ public class HarvestedCollectionRest extends BaseObjectRest<Integer> {
|
||||
this.lastHarvested = lastHarvested;
|
||||
}
|
||||
|
||||
@LinkRest(linkClass = HarvesterMetadataRest.class, name = "harvestermetadata", optional = true)
|
||||
@LinkRest(linkClass = HarvesterMetadataRest.class, name = "harvestermetadata", linkOptional = true)
|
||||
@JsonIgnore
|
||||
public HarvesterMetadataRest getMetadataConfigs() {
|
||||
return metadata_configs;
|
||||
|
@@ -18,10 +18,19 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
*
|
||||
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||
*/
|
||||
@LinksRest(links = {
|
||||
@LinkRest(
|
||||
name = ItemRest.RELATIONSHIPS,
|
||||
linkClass = RelationshipRest.class,
|
||||
method = "getItemRelationships",
|
||||
embedOptional = true
|
||||
)
|
||||
})
|
||||
public class ItemRest extends DSpaceObjectRest {
|
||||
public static final String NAME = "item";
|
||||
public static final String PLURAL_NAME = "items";
|
||||
public static final String CATEGORY = RestAddressableModel.CORE;
|
||||
public static final String RELATIONSHIPS = "relationships";
|
||||
private boolean inArchive = false;
|
||||
private boolean discoverable = false;
|
||||
private boolean withdrawn = false;
|
||||
@@ -32,7 +41,6 @@ public class ItemRest extends DSpaceObjectRest {
|
||||
private CollectionRest templateItemOf;
|
||||
|
||||
List<BundleRest> bundles;
|
||||
List<RelationshipRest> relationships;
|
||||
|
||||
@Override
|
||||
public String getCategory() {
|
||||
@@ -102,14 +110,4 @@ public class ItemRest extends DSpaceObjectRest {
|
||||
public void setBundles(List<BundleRest> bundles) {
|
||||
this.bundles = bundles;
|
||||
}
|
||||
|
||||
@LinkRest(linkClass = RelationshipRest.class)
|
||||
@JsonIgnore
|
||||
public List<RelationshipRest> getRelationships() {
|
||||
return relationships;
|
||||
}
|
||||
|
||||
public void setRelationships(List<RelationshipRest> relationships) {
|
||||
this.relationships = relationships;
|
||||
}
|
||||
}
|
||||
|
@@ -13,8 +13,15 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.dspace.app.rest.model.hateoas.HALResource;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.app.rest.repository.LinkRestRepository;
|
||||
import org.dspace.app.rest.utils.Utils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* This annotation allows to specify the direct linked REST entities
|
||||
* Class or method-level annotation to control linking/embedding behavior when a {@link RestModel}
|
||||
* is wrapped as a {@link HALResource}
|
||||
*
|
||||
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||
*/
|
||||
@@ -22,11 +29,71 @@ import java.lang.annotation.Target;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface LinkRest {
|
||||
|
||||
/**
|
||||
* The rel name to use for the link and/or embed.
|
||||
* <p>
|
||||
* This is optional if the annotation is used at the method level. If unspecified at the method level,
|
||||
* the bean name (inferred by the the name of the method) will be used as the name.
|
||||
* </p>
|
||||
* <p>
|
||||
* This is required if the annotation is used at the class level.
|
||||
* </p>
|
||||
*
|
||||
* @return the name, or the empty string if unspecified by the annotation.
|
||||
*/
|
||||
String name() default "";
|
||||
|
||||
/**
|
||||
* The name of the method to invoke in the associated link repository.
|
||||
* <p>
|
||||
* When this is specified, whether at the class or method level, the value of the resource must be provided
|
||||
* by a {@link LinkRestRepository}, which is found by its {@link Component} name. See
|
||||
* {@link Utils#getResourceRepository(String, String)}} for details.
|
||||
* </p>
|
||||
*
|
||||
* @return the method name, or the empty string if unspecified by the annotation.
|
||||
*/
|
||||
String method() default "";
|
||||
|
||||
/**
|
||||
* The class of object returned by invoking the link method. If a list or page is returned, this should
|
||||
* specify the inner type.
|
||||
*
|
||||
* @return the class.
|
||||
*/
|
||||
Class linkClass();
|
||||
|
||||
boolean optional() default false;
|
||||
/**
|
||||
* Tells whether embedding the resource indicated by this link is optional.
|
||||
* <p>
|
||||
* If false (the default), it means the resource will always be embedded unless the {@link LinkRestRepository}
|
||||
* forbids it via {@link LinkRestRepository#isEmbeddableRelation(Object, String)}.
|
||||
* </p>
|
||||
* <p>
|
||||
* If true, it means the resource will be embedded normally, unless forbidden by the {@link LinkRestRepository}
|
||||
* or the projection, in use, via {@link Projection#allowOptionalEmbed(HALResource, LinkRest)}.
|
||||
* </p>
|
||||
*
|
||||
* @return whether embedding is optional.
|
||||
*/
|
||||
boolean embedOptional() default false;
|
||||
|
||||
/**
|
||||
* Tells whether linking the resource indicated by this link is optional.
|
||||
* <p>
|
||||
* If false (the default), it means the resource will always be linked.
|
||||
* </p>
|
||||
* <p>
|
||||
* If true, it means the resource will only be linked if:
|
||||
* <ul>
|
||||
* <li> The resource is embedded, or</li>
|
||||
* <li> The value returned by the link method is not null and linking is not forbidden by the
|
||||
* projection in use, via {@link Projection#allowOptionalLink(HALResource, LinkRest)}</li>
|
||||
* </ul>
|
||||
* </p>
|
||||
*
|
||||
* @return whether linking is optional.
|
||||
*/
|
||||
boolean linkOptional() default false;
|
||||
}
|
||||
|
@@ -22,5 +22,5 @@ import java.lang.annotation.Target;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface LinksRest {
|
||||
LinkRest[] links();
|
||||
LinkRest[] links() default {};
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ import org.dspace.content.Item;
|
||||
/**
|
||||
* The REST object that will define a list of CollectionRest objects to be returned by the REST api
|
||||
*/
|
||||
public class MappedCollectionRestWrapper implements RestAddressableModel {
|
||||
public class MappedCollectionRestWrapper extends RestAddressableModel {
|
||||
|
||||
@JsonIgnore
|
||||
private List<CollectionRest> mappedCollectionRestList;
|
||||
|
@@ -16,7 +16,7 @@ import org.dspace.app.rest.MappedItemRestController;
|
||||
/**
|
||||
* The REST object that will define a list of ItemRest objects to be returned by the REST api
|
||||
*/
|
||||
public class MappedItemRestWrapper implements RestAddressableModel {
|
||||
public class MappedItemRestWrapper extends RestAddressableModel {
|
||||
|
||||
@JsonIgnore
|
||||
private List<ItemRest> mappedItemRestList;
|
||||
|
@@ -76,4 +76,4 @@ public class MetadataFieldRest extends BaseObjectRest<Integer> {
|
||||
public String getCategory() {
|
||||
return CATEGORY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -54,4 +54,4 @@ public class MetadataSchemaRest extends BaseObjectRest<Integer> {
|
||||
public String getCategory() {
|
||||
return CATEGORY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* 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.model;
|
||||
|
||||
import java.util.AbstractList;
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.app.rest.converter.ConverterService;
|
||||
import org.dspace.app.rest.converter.MetadataConverter;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.content.MetadataValue;
|
||||
|
||||
/**
|
||||
* Type-safe wrapper for a list of {@link MetadataValue}s for use with {@link MetadataConverter},
|
||||
* so it can be invoked properly via calls to {@link ConverterService#toRest(Object, Projection)}.
|
||||
*/
|
||||
public class MetadataValueList extends AbstractList<MetadataValue> {
|
||||
|
||||
private final List<MetadataValue> list;
|
||||
|
||||
public MetadataValueList(List<MetadataValue> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataValue get(int index) {
|
||||
return list.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return list.size();
|
||||
}
|
||||
}
|
@@ -107,4 +107,4 @@ public class PoolTaskRest extends BaseObjectRest<Integer> {
|
||||
public void setWorkflowitem(WorkflowItemRest workflowitem) {
|
||||
this.workflowitem = workflowitem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@ import org.dspace.app.rest.RelationshipTypeRestController;
|
||||
* RelationshipTypeRest objects
|
||||
* The other methods are generic getters and setters
|
||||
*/
|
||||
public class RelationshipTypeRestWrapper implements RestAddressableModel {
|
||||
public class RelationshipTypeRestWrapper extends RestAddressableModel {
|
||||
|
||||
@JsonIgnore
|
||||
private List<RelationshipTypeRest> relationshipTypeRestList;
|
||||
@@ -26,8 +26,6 @@ public class RelationshipTypeRestWrapper implements RestAddressableModel {
|
||||
private String entityTypeLabel;
|
||||
private Integer entityTypeId;
|
||||
|
||||
|
||||
|
||||
public List<RelationshipTypeRest> getRelationshipTypeRestList() {
|
||||
return relationshipTypeRestList;
|
||||
}
|
||||
|
@@ -8,17 +8,29 @@
|
||||
package org.dspace.app.rest.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
|
||||
/**
|
||||
* A directly addressable REST resource
|
||||
*
|
||||
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||
*/
|
||||
public interface RestAddressableModel extends RestModel {
|
||||
public abstract class RestAddressableModel implements RestModel {
|
||||
|
||||
private Projection projection = Projection.DEFAULT;
|
||||
|
||||
@JsonIgnore
|
||||
public String getCategory();
|
||||
public abstract String getCategory();
|
||||
|
||||
@JsonIgnore
|
||||
public Class getController();
|
||||
public abstract Class getController();
|
||||
|
||||
@JsonIgnore
|
||||
public Projection getProjection() {
|
||||
return projection;
|
||||
}
|
||||
|
||||
public void setProjection(Projection projection) {
|
||||
this.projection = projection;
|
||||
}
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@ import org.dspace.app.rest.RootRestResourceController;
|
||||
/**
|
||||
* The purpose of this class is to show the representation of information on the home/root page of the REST API
|
||||
*/
|
||||
public class RootRest implements RestAddressableModel {
|
||||
public class RootRest extends RestAddressableModel {
|
||||
public static final String NAME = "root";
|
||||
public static final String CATEGORY = RestModel.ROOT;
|
||||
private String dspaceURL;
|
||||
|
@@ -29,19 +29,6 @@ public class SearchEventRest extends BaseObjectRest<UUID> {
|
||||
private SearchResultsRest.Sorting sort;
|
||||
private PageRest page;
|
||||
|
||||
public SearchEventRest(String query, UUID scope, String configuration,
|
||||
List<SearchResultsRest.AppliedFilter> appliedFilters,
|
||||
SearchResultsRest.Sorting sort) {
|
||||
this.query = query;
|
||||
this.scope = scope;
|
||||
this.configuration = configuration;
|
||||
this.appliedFilters = appliedFilters;
|
||||
this.sort = sort;
|
||||
}
|
||||
|
||||
public SearchEventRest() {
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return CATEGORY;
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@ import org.dspace.discovery.configuration.DiscoverySearchFilterFacet;
|
||||
/**
|
||||
* This class' purpose is to create a container for the information used in the SearchFacetEntryResource
|
||||
*/
|
||||
public class SearchFacetEntryRest implements RestAddressableModel {
|
||||
public class SearchFacetEntryRest extends RestAddressableModel {
|
||||
|
||||
public static final String NAME = "discover";
|
||||
public static final String CATEGORY = RestModel.DISCOVER;
|
||||
|
@@ -13,7 +13,7 @@ import org.dspace.app.rest.DiscoveryRestController;
|
||||
/**
|
||||
* This class' purpose is to create a container for the information used in the SearchFacetValueResource
|
||||
*/
|
||||
public class SearchFacetValueRest implements RestAddressableModel {
|
||||
public class SearchFacetValueRest extends RestAddressableModel {
|
||||
|
||||
public static final String NAME = "discover";
|
||||
public static final String CATEGORY = RestModel.DISCOVER;
|
||||
|
@@ -12,13 +12,12 @@ 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
|
||||
*/
|
||||
public class SearchResultEntryRest implements RestAddressableModel {
|
||||
public class SearchResultEntryRest extends RestAddressableModel {
|
||||
|
||||
public static final String NAME = "discover";
|
||||
public static final String CATEGORY = RestModel.DISCOVER;
|
||||
|
@@ -11,7 +11,6 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
@@ -29,7 +28,6 @@ public class SearchResultsRest extends DiscoveryResultsRest {
|
||||
@JsonIgnore
|
||||
List<SearchFacetEntryRest> facets;
|
||||
|
||||
|
||||
public List<SearchResultEntryRest> getSearchResults() {
|
||||
return searchResults;
|
||||
}
|
||||
|
@@ -86,4 +86,4 @@ public class SubmissionDefinitionRest extends BaseObjectRest<String> {
|
||||
public void setCollections(List<CollectionRest> collections) {
|
||||
this.collections = collections;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -97,4 +97,4 @@ public class SubmissionUploadRest extends BaseObjectRest<String> {
|
||||
public void setMetadata(SubmissionFormRest metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -32,4 +32,4 @@ public class WorkflowItemRest extends AInprogressSubmissionRest<Integer> {
|
||||
public Class getController() {
|
||||
return RestResourceController.class;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -32,4 +32,4 @@ public class WorkspaceItemRest extends AInprogressSubmissionRest<Integer> {
|
||||
public Class getController() {
|
||||
return RestResourceController.class;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user