DS-3533 Apply projections uniformly

This commit is contained in:
Chris Wilper
2019-11-05 09:44:12 -05:00
parent 640c9071ef
commit 7eb1508387
110 changed files with 580 additions and 444 deletions

View File

@@ -19,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;
@@ -70,20 +71,23 @@ public class AuthenticationRestController implements InitializingBean {
@RequestMapping(method = RequestMethod.GET)
public AuthnResource authn() {
AuthnResource authnResource = converter.toResource(new AuthnRest());
return authnResource;
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 = converter.toResource(
new AuthenticationStatusRest(ePersonRest));
AuthenticationStatusRest authenticationStatusRest = new AuthenticationStatusRest(ePersonRest);
authenticationStatusRest.setProjection(projection);
AuthenticationStatusResource authenticationStatusResource = converter.toResource(authenticationStatusRest);
return authenticationStatusResource;
}

View File

@@ -26,6 +26,7 @@ import org.dspace.app.rest.converter.ConverterService;
import org.dspace.app.rest.exception.DSpaceBadRequestException;
import org.dspace.app.rest.model.BitstreamRest;
import org.dspace.app.rest.model.hateoas.BitstreamResource;
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;
@@ -238,6 +239,7 @@ public class BitstreamRestController {
context.commit();
return converter.toResource(converter.toRest(context.reloadEntity(bitstream)));
BitstreamRest bitstreamRest = converter.toRest(context.reloadEntity(bitstream), Projection.DEFAULT);
return converter.toResource(bitstreamRest);
}
}

View File

@@ -143,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);

View File

@@ -18,7 +18,6 @@ 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;
@@ -50,10 +49,11 @@ 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 = converter.toResource(data);

View File

@@ -13,7 +13,6 @@ 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;
@@ -22,6 +21,7 @@ import org.atteo.evo.inflector.English;
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;
@@ -55,6 +55,9 @@ public class IdentifierRestController implements InitializingBean {
@Autowired
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.toRest(dso);
DSpaceObjectRest dsor = converter.toRest(dso, utils.obtainProjection());
URI link = linkTo(dsor.getController(), dsor.getCategory(),
English.plural(dsor.getType()))
.slash(dsor.getId()).toUri();

View File

@@ -20,6 +20,7 @@ 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;
@@ -97,7 +98,7 @@ public class ItemOwningCollectionUpdateRestController {
if (targetCollection == null) {
return null;
}
return converter.toRest(targetCollection);
return converter.toRest(targetCollection, Projection.DEFAULT);
}

View File

@@ -22,6 +22,7 @@ import org.dspace.app.rest.converter.MetadataConverter;
import org.dspace.app.rest.exception.UnprocessableEntityException;
import org.dspace.app.rest.model.BitstreamRest;
import org.dspace.app.rest.model.hateoas.BitstreamResource;
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;
@@ -109,7 +110,7 @@ public class ItemUploadController {
log.error(message, e);
throw new RuntimeException(message, e);
}
return converter.toResource(converter.toRest(bitstream));
return converter.toResource(converter.toRest(bitstream, Projection.DEFAULT));
}
/**

View File

@@ -100,11 +100,12 @@ public class MappedCollectionRestController {
List<CollectionRest> mappingCollectionRest = new LinkedList<>();
for (Collection collection : collections) {
if (collection.getID() != owningCollectionUuid) {
mappingCollectionRest.add(converter.toRest(collection));
mappingCollectionRest.add(converter.toRest(collection, utils.obtainProjection()));
}
}
MappedCollectionRestWrapper mappingCollectionRestWrapper = new MappedCollectionRestWrapper();
mappingCollectionRestWrapper.setProjection(utils.obtainProjection());
mappingCollectionRestWrapper.setMappedCollectionRestList(mappingCollectionRest);
mappingCollectionRestWrapper.setItem(item);
MappedCollectionResourceWrapper mappingCollectionResourceWrapper =

View File

@@ -95,11 +95,12 @@ public class MappedItemRestController {
while (itemIterator.hasNext()) {
Item item = itemIterator.next();
if (item.getOwningCollection().getID() != uuid) {
mappedItemRestList.add(converter.toRest(item));
mappedItemRestList.add(converter.toRest(item, utils.obtainProjection()));
}
}
MappedItemRestWrapper mappedItemRestWrapper = new MappedItemRestWrapper();
mappedItemRestWrapper.setProjection(utils.obtainProjection());
mappedItemRestWrapper.setMappedItemRestList(mappedItemRestList);
mappedItemRestWrapper.setCollectionUuid(uuid);
MappedItemResourceWrapper mappedItemResourceWrapper =

View File

@@ -18,6 +18,7 @@ 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;
@@ -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,12 +77,13 @@ public class RelationshipTypeRestController {
List<RelationshipTypeRest> relationshipTypeRests = new LinkedList<>();
Projection projection = utils.obtainProjection();
for (RelationshipType relationshipType : list) {
relationshipTypeRests.add(converter.toRest(relationshipType));
relationshipTypeRests.add(converter.toRest(relationshipType, projection));
}
RelationshipTypeRestWrapper relationshipTypeRestWrapper = new RelationshipTypeRestWrapper();
relationshipTypeRestWrapper.setProjection(projection);
relationshipTypeRestWrapper.setEntityTypeId(id);
relationshipTypeRestWrapper.setEntityTypeLabel(entityType.getLabel());
relationshipTypeRestWrapper.setRelationshipTypeRestList(relationshipTypeRests);

View File

@@ -160,15 +160,13 @@ public class RestResourceController implements InitializingBean {
* @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);
}
/**
@@ -194,15 +192,13 @@ public class RestResourceController implements InitializingBean {
* @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);
}
/**
@@ -217,15 +213,13 @@ public class RestResourceController implements InitializingBean {
* @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);
}
/**
@@ -234,13 +228,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 {
@@ -266,7 +257,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}")
@@ -274,9 +264,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);
}
/**
@@ -292,7 +281,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 +
@@ -301,9 +289,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);
}
/**
@@ -318,7 +305,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}")
@@ -326,9 +312,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);
}
/**
@@ -361,7 +346,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 +
@@ -370,9 +354,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);
}
@@ -751,7 +734,6 @@ public class RestResourceController implements InitializingBean {
* @param relid
* @param page
* @param assembler
* @param projection
* @return
*/
private <ID extends Serializable> ResourceSupport findRelEntryInternal(HttpServletRequest request,
@@ -759,8 +741,8 @@ 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();
@@ -770,7 +752,7 @@ public class RestResourceController implements InitializingBean {
LinkRestRepository linkRepository = utils.getLinkResourceRepository(apiCategory, model, linkRest.name());
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();
@@ -803,17 +785,15 @@ 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();
@@ -827,7 +807,7 @@ public class RestResourceController implements InitializingBean {
try {
if (Page.class.isAssignableFrom(linkMethod.getReturnType())) {
Page<? extends RestModel> pageResult = (Page<? extends RestAddressableModel>) linkMethod
.invoke(linkRepository, request, uuid, page, projection);
.invoke(linkRepository, request, uuid, page, utils.obtainProjection(true));
Link link = null;
String querystring = request.getQueryString();
@@ -842,7 +822,7 @@ public class RestResourceController implements InitializingBean {
return assembler.toResource(halResources, link);
} else {
RestModel object = (RestModel) linkMethod.invoke(linkRepository, request, uuid, page,
projection);
utils.obtainProjection());
Link link = linkTo(this.getClass(), apiCategory, model).slash(uuid).slash(subpath)
.withSelfRel();
HALResource tmpresult = converter.toResource(object);
@@ -917,7 +897,6 @@ public class RestResourceController implements InitializingBean {
* @param model
* @param page
* @param assembler
* @param projection
* @return
*/
@RequestMapping(method = RequestMethod.GET)
@@ -926,12 +905,10 @@ 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;

View File

@@ -21,6 +21,7 @@ import org.apache.log4j.Logger;
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;
@@ -56,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);
@@ -91,7 +95,7 @@ public class UUIDLookupRestController implements InitializingBean {
.getDSpaceObjectServices()) {
DSpaceObject dso = dSpaceObjectService.find(context, uuid);
if (dso != null) {
DSpaceObjectRest dsor = converter.toRest(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);

View File

@@ -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;
@@ -61,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;
@@ -72,9 +73,9 @@ public abstract class AInprogressItemConverter<T extends InProgressSubmission<ID
}
witem.setId(obj.getID());
witem.setCollection(collection != null ? converter.toRest(collection) : null);
witem.setItem(converter.toRest(item));
witem.setSubmitter(converter.toRest(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
@@ -82,7 +83,7 @@ public abstract class AInprogressItemConverter<T extends InProgressSubmission<ID
if (collection != null) {
SubmissionDefinitionRest def = converter.toRest(
submissionConfigReader.getSubmissionConfigByCollection(collection.getHandle()));
submissionConfigReader.getSubmissionConfigByCollection(collection.getHandle()), projection);
witem.setSubmissionDefinition(def);
for (SubmissionSectionRest sections : def.getPanels()) {
SubmissionStepConfig stepConfig = submissionSectionConverter.toModel(sections);

View File

@@ -8,6 +8,7 @@
package org.dspace.app.rest.converter;
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;
@@ -16,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)
*/
@@ -24,8 +25,9 @@ import org.springframework.stereotype.Component;
public class AuthorityEntryRestConverter implements DSpaceConverter<Choice, AuthorityEntryRest> {
@Override
public AuthorityEntryRest convert(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);

View File

@@ -8,6 +8,7 @@
package org.dspace.app.rest.converter;
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;
@@ -17,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)
*/
@@ -25,8 +26,9 @@ import org.springframework.stereotype.Component;
public class AuthorityRestConverter implements DSpaceConverter<ChoiceAuthority, AuthorityRest> {
@Override
public AuthorityRest convert(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());

View File

@@ -12,6 +12,7 @@ import java.util.List;
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;
@@ -24,15 +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> {
public class BitstreamConverter extends DSpaceObjectConverter<Bitstream, BitstreamRest> {
@Autowired
ConverterService converter;
@Override
public BitstreamRest convert(org.dspace.content.Bitstream obj) {
BitstreamRest b = super.convert(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 {
@@ -49,7 +49,7 @@ public class BitstreamConverter
checksum.setValue(obj.getChecksum());
b.setCheckSum(checksum);
try {
b.setFormat(converter.toRest(obj.getFormat(null)));
b.setFormat(converter.toRest(obj.getFormat(null), projection));
} catch (SQLException e) {
throw new RuntimeException(e);
}

View File

@@ -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 convert(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());

View File

@@ -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;
@@ -26,8 +27,9 @@ import org.springframework.stereotype.Component;
public class BrowseIndexConverter implements DSpaceConverter<BrowseIndex, BrowseIndexRest> {
@Override
public BrowseIndexRest convert(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());

View File

@@ -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,21 +23,21 @@ import org.springframework.stereotype.Component;
*/
@Component
public class ClaimedTaskConverter
implements IndexableObjectConverter<ClaimedTask, org.dspace.app.rest.model.ClaimedTaskRest> {
implements IndexableObjectConverter<ClaimedTask, ClaimedTaskRest> {
@Autowired
private ConverterService converter;
@Override
public ClaimedTaskRest convert(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(converter.toRest(witem));
taskRest.setWorkflowitem(converter.toRest(witem, projection));
taskRest.setAction(obj.getActionID());
taskRest.setStep(obj.getStepID());
taskRest.setOwner(converter.toRest(obj.getOwner()));
taskRest.setOwner(converter.toRest(obj.getOwner(), projection));
return taskRest;
}

View File

@@ -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;
@@ -53,19 +54,19 @@ public class CollectionConverter
private AuthorizeService authorizeService;
@Override
public CollectionRest convert(org.dspace.content.Collection obj) {
CollectionRest col = super.convert(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(converter.toRest(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();
@@ -88,7 +89,7 @@ public class CollectionConverter
List<ResourcePolicyRest> results = new ArrayList<ResourcePolicyRest>();
for (ResourcePolicy pp : defaultCollectionPolicies) {
ResourcePolicyRest accessCondition = converter.toRest(pp);
ResourcePolicyRest accessCondition = converter.toRest(pp, projection);
if (accessCondition != null) {
results.add(accessCondition);
}

View File

@@ -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;
@@ -34,17 +35,17 @@ public class CommunityConverter
private ConverterService converter;
@Override
public CommunityRest convert(org.dspace.content.Community obj) {
CommunityRest com = super.convert(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(converter.toRest(logo));
com.setLogo(converter.toRest(logo, projection));
}
List<Collection> collections = obj.getCollections();
List<CollectionRest> collectionsRest = new ArrayList<>();
if (collections != null) {
for (Collection col : collections) {
collectionsRest.add(converter.toRest(col));
collectionsRest.add(converter.toRest(col, projection));
}
}
com.setCollections(collectionsRest);
@@ -53,7 +54,7 @@ public class CommunityConverter
List<CommunityRest> communityRest = new ArrayList<>();
if (subCommunities != null) {
for (Community scom : subCommunities) {
CommunityRest scomrest = this.convert(scom);
CommunityRest scomrest = this.convert(scom, projection);
communityRest.add(scomrest);
}
}

View File

@@ -61,36 +61,17 @@ public class ConverterService {
private List<Projection> projections;
/**
* Converts the given model object to rest object, using the appropriate {@link DSpaceConverter}.
*
* @param modelObject the model object, which may be a JPA entity or other class provided by the DSpace
* service layer.
* @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 {@link DefaultProjection}.
* @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) {
return toRest(modelObject, null);
}
/**
* Converts the given model object to a rest object, using the appropriate {@link DSpaceConverter}.
* 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.
* If the rest object is a {@link RestAddressableModel}, its {@code projection} field will also be set so
* that a subsequent call to {@link #toResource(RestModel)} will respect the projection without it
* having to be provided as an argument again.
* </p>
*
* @param modelObject the model object, which may be a JPA entity or other class provided by the DSpace
* service layer.
* @param projectionName the name of the projection to use. If given as {@code null}, the default no-op
* projection, {@link DefaultProjection} will be used.
* @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
@@ -98,17 +79,11 @@ public class ConverterService {
* @throws IllegalArgumentException if there is no compatible converter or no such projection.
* @throws ClassCastException if the converter's return type is not compatible with the inferred return type.
*/
public <M, R> R toRest(M modelObject, @Nullable String projectionName) {
Projection projection = projectionName == null ? Projection.DEFAULT : requireProjection(projectionName);
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);
R restObject = converter.convert(transformedModel, projection);
if (restObject instanceof RestModel) {
if (restObject instanceof RestAddressableModel) {
RestAddressableModel ram = projection.transformRest((RestAddressableModel) restObject);
ram.setProjection(projection);
return (R) ram;
}
return (R) projection.transformRest((RestModel) restObject);
}
return restObject;
@@ -127,26 +102,6 @@ public class ConverterService {
return (DSpaceConverter<M, R>) requireConverter(sourceClass);
}
/**
* Converts the given rest object to a {@link HALResource} object, assigning the named projection beforehand,
* if it is a {@link RestAddressableModel}.
* <p>
* After the projection is assigned, behavior of this method is exactly the same as {@link #toResource(RestModel)}.
* </p>
*
* @param restObject the input rest object.
* @param projectionName the name of the projection to assign and use.
* @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 such projection.
*/
public <T extends HALResource> T toResource(RestModel restObject, String projectionName) {
if (restObject instanceof RestAddressableModel) {
((RestAddressableModel) restObject).setProjection(requireProjection(projectionName));
}
return toResource(restObject);
}
/**
* Converts the given rest object to a {@link HALResource} object.
* <p>
@@ -177,6 +132,17 @@ public class ConverterService {
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>

View File

@@ -7,8 +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> {
R convert(M restObject, Projection projection);
public interface DSpaceConverter<M, R> extends Converter<M, R> {
Class<M> getModelClass();
}

View File

@@ -7,6 +7,7 @@
*/
package org.dspace.app.rest.converter;
import org.dspace.app.rest.projection.Projection;
import org.dspace.content.DSpaceObject;
import org.springframework.beans.factory.annotation.Autowired;
@@ -25,8 +26,9 @@ public abstract class DSpaceObjectConverter<M extends DSpaceObject, R extends or
private MetadataConverter metadataConverter;
@Override
public R convert(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());

View File

@@ -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;

View File

@@ -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()) {

View File

@@ -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());

View File

@@ -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 {

View File

@@ -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;

View File

@@ -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;
@@ -39,8 +40,8 @@ public class EPersonConverter extends DSpaceObjectConverter<EPerson, org.dspace.
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(EPersonConverter.class);
@Override
public EPersonRest convert(EPerson obj) {
EPersonRest eperson = super.convert(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,12 +52,13 @@ public class EPersonConverter extends DSpaceObjectConverter<EPerson, org.dspace.
return eperson;
}
public EPersonRest fromModelWithGroups(Context context, EPerson ePerson) throws SQLException {
EPersonRest eperson = convert(ePerson);
public EPersonRest fromModelWithGroups(Context context, EPerson ePerson, Projection projection)
throws SQLException {
EPersonRest eperson = convert(ePerson, projection);
List<GroupRest> groups = new ArrayList<>();
for (Group g : groupService.allMemberGroups(context, ePerson)) {
groups.add(converter.toRest(g));
groups.add(converter.toRest(g, projection));
}
eperson.setGroups(groups);

View File

@@ -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,15 +19,10 @@ 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
*/
@Override
public EntityTypeRest convert(EntityType obj) {
public EntityTypeRest convert(EntityType obj, Projection projection) {
EntityTypeRest entityTypeRest = new EntityTypeRest();
entityTypeRest.setProjection(projection);
entityTypeRest.setId(obj.getID());
entityTypeRest.setLabel(obj.getLabel());
return entityTypeRest;

View File

@@ -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,12 +28,12 @@ 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 convert(Group obj) {
GroupRest epersongroup = super.convert(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);

View File

@@ -14,6 +14,7 @@ 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;
@@ -31,15 +32,16 @@ public class HarvestedCollectionConverter implements DSpaceConverter<HarvestedCo
private ConverterService converter;
@Override
public HarvestedCollectionRest convert(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(converter.toRest(obj.getCollection()));
harvestedCollectionRest.setCollection(converter.toRest(obj.getCollection(), projection));
harvestedCollectionRest.setHarvestType(harvestTypeEnum);
harvestedCollectionRest.setHarvestStatus(harvestStatusEnum);
harvestedCollectionRest.setMetadataConfigId(obj.getHarvestMetadataConfig());
@@ -58,17 +60,18 @@ public class HarvestedCollectionConverter implements DSpaceConverter<HarvestedCo
public HarvestedCollectionRest fromModel(HarvestedCollection obj,
Collection collection,
List<Map<String,String>> metadata_configs) {
HarvestedCollectionRest harvestedCollectionRest = this.convert(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(converter.toRest(collection));
harvestedCollectionRest.setCollection(converter.toRest(collection, projection));
}
HarvesterMetadataRest harvesterMetadataRest = new HarvesterMetadataRest();
harvesterMetadataRest.setProjection(projection);
harvesterMetadataRest.setConfigs(metadata_configs);
harvestedCollectionRest.setMetadataConfigs(harvesterMetadataRest);
return harvestedCollectionRest;

View File

@@ -13,6 +13,7 @@ import java.util.List;
import org.apache.logging.log4j.Logger;
import org.dspace.app.rest.model.BitstreamRest;
import org.dspace.app.rest.model.ItemRest;
import org.dspace.app.rest.projection.Projection;
import org.dspace.content.Bitstream;
import org.dspace.content.Bundle;
import org.dspace.content.Collection;
@@ -31,7 +32,7 @@ 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
@@ -44,24 +45,24 @@ public class ItemConverter
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(ItemConverter.class);
@Override
public ItemRest convert(org.dspace.content.Item obj) {
ItemRest item = super.convert(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());
Collection owningCollection = obj.getOwningCollection();
if (owningCollection != null) {
item.setOwningCollection(converter.toRest(owningCollection));
item.setOwningCollection(converter.toRest(owningCollection, projection));
}
Collection templateItemOf = obj.getTemplateItemOf();
if (templateItemOf != null) {
item.setTemplateItemOf(converter.toRest(templateItemOf));
item.setTemplateItemOf(converter.toRest(templateItemOf, projection));
}
List<BitstreamRest> bitstreams = new ArrayList<>();
for (Bundle bun : obj.getBundles()) {
for (Bitstream bit : bun.getBitstreams()) {
bitstreams.add(converter.toRest(bit));
bitstreams.add(converter.toRest(bit, projection));
}
}
item.setBitstreams(bitstreams);

View File

@@ -18,6 +18,7 @@ import java.util.stream.Collectors;
import org.dspace.app.rest.model.MetadataRest;
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;
@@ -58,7 +59,7 @@ public class MetadataConverter implements Converter<List<MetadataValue>, Metadat
set = new TreeSet<>(Comparator.comparingInt(MetadataValueRest::getPlace));
mapOfSortedSets.put(key, set);
}
set.add(converter.toRest(metadataValue));
set.add(converter.toRest(metadataValue, Projection.DEFAULT));
}
MetadataRest metadataRest = new MetadataRest();

View File

@@ -8,6 +8,7 @@
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;
@@ -19,18 +20,19 @@ import org.springframework.stereotype.Component;
* @author Andrea Bollini (andrea.bollini at 4science.it)
*/
@Component
public class MetadataFieldConverter implements DSpaceConverter<org.dspace.content.MetadataField, MetadataFieldRest> {
public class MetadataFieldConverter implements DSpaceConverter<MetadataField, MetadataFieldRest> {
@Autowired
private ConverterService converter;
@Override
public MetadataFieldRest convert(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(converter.toRest(obj.getMetadataSchema()));
field.setSchema(converter.toRest(obj.getMetadataSchema(), projection));
return field;
}

View File

@@ -8,6 +8,7 @@
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;
@@ -18,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 convert(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());

View File

@@ -8,6 +8,7 @@
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.stereotype.Component;
@@ -17,14 +18,8 @@ import org.springframework.stereotype.Component;
@Component
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());

View File

@@ -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;
@@ -28,17 +29,18 @@ public class PoolTaskConverter
private ConverterService converter;
@Override
public PoolTaskRest convert(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(converter.toRest(witem));
taskRest.setWorkflowitem(converter.toRest(witem, projection));
if (obj.getEperson() != null) {
taskRest.setEperson(converter.toRest(obj.getEperson()));
taskRest.setEperson(converter.toRest(obj.getEperson(), projection));
}
if (obj.getGroup() != null) {
taskRest.setGroup(converter.toRest(obj.getGroup()));
taskRest.setGroup(converter.toRest(obj.getGroup(), projection));
}
taskRest.setAction(obj.getActionID());
taskRest.setStep(obj.getStepID());

View File

@@ -8,6 +8,7 @@
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;
@@ -22,17 +23,13 @@ public class RelationshipConverter implements DSpaceConverter<Relationship, Rela
@Autowired
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 convert(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(converter.toRest(obj.getRelationshipType()));
relationshipRest.setRelationshipType(converter.toRest(obj.getRelationshipType(), projection));
relationshipRest.setRightId(obj.getRightItem().getID());
relationshipRest.setLeftPlace(obj.getLeftPlace());
relationshipRest.setRightPlace(obj.getRightPlace());

View File

@@ -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;
@@ -22,14 +23,10 @@ public class RelationshipTypeConverter implements DSpaceConverter<RelationshipTy
@Autowired
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 convert(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,8 +35,8 @@ public class RelationshipTypeConverter implements DSpaceConverter<RelationshipTy
relationshipTypeRest.setLeftMaxCardinality(obj.getLeftMaxCardinality());
relationshipTypeRest.setRightMinCardinality(obj.getRightMinCardinality());
relationshipTypeRest.setRightMaxCardinality(obj.getRightMaxCardinality());
relationshipTypeRest.setLeftType(converter.toRest(obj.getLeftType()));
relationshipTypeRest.setRightType(converter.toRest(obj.getRightType()));
relationshipTypeRest.setLeftType(converter.toRest(obj.getLeftType(), projection));
relationshipTypeRest.setRightType(converter.toRest(obj.getRightType(), projection));
return relationshipTypeRest;
}

View File

@@ -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 convert(ResourcePolicy obj) {
public ResourcePolicyRest convert(ResourcePolicy obj, Projection projection) {
ResourcePolicyRest model = new ResourcePolicyRest();
model.setProjection(projection);
model.setId(obj.getID());

View File

@@ -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,12 +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> {
public class SiteConverter extends DSpaceObjectConverter<Site, SiteRest> {
@Override
public SiteRest convert(org.dspace.content.Site obj) {
return super.convert(obj);
public SiteRest convert(Site obj, Projection projection) {
return super.convert(obj, projection);
}
@Override

View File

@@ -17,6 +17,7 @@ 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;
@@ -49,14 +50,15 @@ public class SubmissionDefinitionConverter implements DSpaceConverter<Submission
private ConverterService converter;
@Override
public SubmissionDefinitionRest convert(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 = converter.toRest(step);
SubmissionSectionRest sp = converter.toRest(step, projection);
panels.add(sp);
}
@@ -68,7 +70,8 @@ public class SubmissionDefinitionConverter implements DSpaceConverter<Submission
.getCollectionsBySubmissionConfig(context,
obj.getSubmissionName());
DSpaceConverter<Collection, CollectionRest> cc = converter.getConverter(Collection.class);
List<CollectionRest> collectionsRest = collections.stream().map(cc::convert).collect(Collectors.toList());
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);

View File

@@ -21,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;
@@ -50,8 +51,9 @@ public class SubmissionFormConverter implements DSpaceConverter<DCInputSet, Subm
private SubmissionFormRestRepository submissionFormRestRepository;
@Override
public SubmissionFormRest convert(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());

View File

@@ -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 convert(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());

View File

@@ -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,9 +30,10 @@ public class WorkflowItemConverter
}
@Override
public WorkflowItemRest convert(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;
}

View File

@@ -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,10 +29,10 @@ public class WorkspaceItemConverter
}
@Override
public WorkspaceItemRest convert(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;
}

View File

@@ -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));
}

View File

@@ -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);

View File

@@ -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(

View File

@@ -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

View File

@@ -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

View File

@@ -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;
}
}
}

View File

@@ -101,4 +101,4 @@ public class BitstreamFormatRest extends BaseObjectRest<Integer> {
public Class getController() {
return RestResourceController.class;
}
}
}

View File

@@ -92,4 +92,4 @@ public class ClaimedTaskRest extends BaseObjectRest<Integer> {
public void setWorkflowitem(WorkflowItemRest workflowitem) {
this.workflowitem = workflowitem;
}
}
}

View File

@@ -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;

View File

@@ -123,4 +123,4 @@ public class EPersonRest extends DSpaceObjectRest {
return RestResourceController.class;
}
}
}

View File

@@ -76,4 +76,4 @@ public class MetadataFieldRest extends BaseObjectRest<Integer> {
public String getCategory() {
return CATEGORY;
}
}
}

View File

@@ -54,4 +54,4 @@ public class MetadataSchemaRest extends BaseObjectRest<Integer> {
public String getCategory() {
return CATEGORY;
}
}
}

View File

@@ -107,4 +107,4 @@ public class PoolTaskRest extends BaseObjectRest<Integer> {
public void setWorkflowitem(WorkflowItemRest workflowitem) {
this.workflowitem = workflowitem;
}
}
}

View File

@@ -26,8 +26,6 @@ public class RelationshipTypeRestWrapper extends RestAddressableModel {
private String entityTypeLabel;
private Integer entityTypeId;
public List<RelationshipTypeRest> getRelationshipTypeRestList() {
return relationshipTypeRestList;
}

View File

@@ -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;
}

View File

@@ -12,7 +12,6 @@ import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.dspace.app.rest.DiscoveryRestController;
/**

View File

@@ -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;
}

View File

@@ -86,4 +86,4 @@ public class SubmissionDefinitionRest extends BaseObjectRest<String> {
public void setCollections(List<CollectionRest> collections) {
this.collections = collections;
}
}
}

View File

@@ -97,4 +97,4 @@ public class SubmissionUploadRest extends BaseObjectRest<String> {
public void setMetadata(SubmissionFormRest metadata) {
this.metadata = metadata;
}
}
}

View File

@@ -32,4 +32,4 @@ public class WorkflowItemRest extends AInprogressSubmissionRest<Integer> {
public Class getController() {
return RestResourceController.class;
}
}
}

View File

@@ -32,4 +32,4 @@ public class WorkspaceItemRest extends AInprogressSubmissionRest<Integer> {
public Class getController() {
return RestResourceController.class;
}
}
}

View File

@@ -16,6 +16,7 @@ import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.dspace.app.rest.model.AuthorityEntryRest;
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.Collection;
import org.dspace.content.authority.Choice;
@@ -50,7 +51,7 @@ public class AuthorityEntryLinkRepository extends AbstractDSpaceRestRepository
@PreAuthorize("hasAuthority('AUTHENTICATED')")
public Page<AuthorityEntryRest> query(HttpServletRequest request, String name,
Pageable pageable, String projection) {
Pageable pageable, Projection projection) {
Context context = obtainContext();
String query = request.getParameter("query");
String metadata = request.getParameter("metadata");
@@ -63,17 +64,17 @@ public class AuthorityEntryLinkRepository extends AbstractDSpaceRestRepository
throw new RuntimeException(e);
}
}
List<AuthorityEntryRest> results = new ArrayList<AuthorityEntryRest>();
List<AuthorityEntryRest> results = new ArrayList<>();
if (StringUtils.isNotBlank(metadata)) {
String[] tokens = org.dspace.core.Utils.tokenize(metadata);
String fieldKey = org.dspace.core.Utils.standardize(tokens[0], tokens[1], tokens[2], "_");
Choices choices = cas.getMatches(fieldKey, query, collection, pageable.getOffset(), pageable.getPageSize(),
context.getCurrentLocale().toString());
for (Choice value : choices.values) {
results.add(authorityUtils.convertEntry(value, name));
results.add(authorityUtils.convertEntry(value, name, projection));
}
}
return new PageImpl<AuthorityEntryRest>(results, pageable, results.size());
return new PageImpl<>(results, pageable, results.size());
}
}

View File

@@ -11,6 +11,7 @@ import javax.servlet.http.HttpServletRequest;
import org.dspace.app.rest.model.AuthorityEntryRest;
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.Choice;
import org.dspace.content.authority.ChoiceAuthority;
@@ -39,14 +40,14 @@ public class AuthorityEntryValueLinkRepository extends AbstractDSpaceRestReposit
@PreAuthorize("hasAuthority('AUTHENTICATED')")
public AuthorityEntryRest getResource(HttpServletRequest request, String name, String relId,
Pageable pageable, String projection) {
Pageable pageable, Projection projection) {
Context context = obtainContext();
ChoiceAuthority choiceAuthority = cas.getChoiceAuthorityByAuthorityName(name);
Choice choice = choiceAuthority.getChoice(null, relId, context.getCurrentLocale().toString());
if (choice == null) {
throw new ResourceNotFoundException("The authority was not found");
}
return authorityUtils.convertEntry(choice, name);
return authorityUtils.convertEntry(choice, name, projection);
}
}

View File

@@ -12,6 +12,7 @@ import java.util.List;
import java.util.Set;
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.dspace.content.authority.service.ChoiceAuthorityService;
@@ -41,7 +42,7 @@ public class AuthorityRestRepository extends DSpaceRestRepository<AuthorityRest,
@Override
public AuthorityRest findOne(Context context, String name) {
ChoiceAuthority source = cas.getChoiceAuthorityByAuthorityName(name);
AuthorityRest result = authorityUtils.convertAuthority(source, name);
AuthorityRest result = authorityUtils.convertAuthority(source, name, utils.obtainProjection());
return result;
}
@@ -50,9 +51,10 @@ public class AuthorityRestRepository extends DSpaceRestRepository<AuthorityRest,
public Page<AuthorityRest> findAll(Context context, Pageable pageable) {
Set<String> authoritiesName = cas.getChoiceAuthoritiesNames();
List<AuthorityRest> results = new ArrayList<AuthorityRest>();
Projection projection = utils.obtainProjection(true);
for (String authorityName : authoritiesName) {
ChoiceAuthority source = cas.getChoiceAuthorityByAuthorityName(authorityName);
AuthorityRest result = authorityUtils.convertAuthority(source, authorityName);
AuthorityRest result = authorityUtils.convertAuthority(source, authorityName, projection);
results.add(result);
}
return new PageImpl<AuthorityRest>(results, pageable, results.size());

View File

@@ -19,6 +19,7 @@ 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.BitstreamFormatRest;
import org.dspace.app.rest.projection.Projection;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.BitstreamFormat;
import org.dspace.content.service.BitstreamFormatService;
@@ -61,7 +62,7 @@ public class BitstreamFormatRestRepository extends DSpaceRestRepository<Bitstrea
if (bit == null) {
return null;
}
return converter.toRest(bit);
return converter.toRest(bit, utils.obtainProjection());
}
@Override
@@ -72,7 +73,9 @@ public class BitstreamFormatRestRepository extends DSpaceRestRepository<Bitstrea
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
Page<BitstreamFormatRest> page = utils.getPage(bit, pageable).map(converter::toRest);
Projection projection = utils.obtainProjection(true);
Page<BitstreamFormatRest> page = utils.getPage(bit, pageable)
.map((object) -> converter.toRest(object, projection));
return page;
}
@@ -99,7 +102,7 @@ public class BitstreamFormatRestRepository extends DSpaceRestRepository<Bitstrea
+ bitstreamFormatRest.getShortDescription(), e);
}
return converter.toRest(bitstreamFormat);
return converter.toRest(bitstreamFormat, Projection.DEFAULT);
}
@Override
@@ -126,7 +129,7 @@ public class BitstreamFormatRestRepository extends DSpaceRestRepository<Bitstrea
if (id.equals(bitstreamFormatRest.getId())) {
this.setAllValuesOfRest(context, bitstreamFormat, bitstreamFormatRest);
bitstreamFormatService.update(context, bitstreamFormat);
return converter.toRest(bitstreamFormat);
return converter.toRest(bitstreamFormat, Projection.DEFAULT);
} else {
throw new IllegalArgumentException("The id in the Json and the id in the url do not match: "
+ id + ", "

View File

@@ -19,6 +19,7 @@ import javax.servlet.http.HttpServletRequest;
import org.dspace.app.rest.exception.UnprocessableEntityException;
import org.dspace.app.rest.model.BitstreamRest;
import org.dspace.app.rest.model.patch.Patch;
import org.dspace.app.rest.projection.Projection;
import org.dspace.app.rest.repository.patch.DSpaceObjectPatch;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Bitstream;
@@ -69,7 +70,7 @@ public class BitstreamRestRepository extends DSpaceObjectRestRepository<Bitstrea
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
return converter.toRest(bit);
return converter.toRest(bit, utils.obtainProjection());
}
@Override
@@ -87,7 +88,9 @@ public class BitstreamRestRepository extends DSpaceObjectRestRepository<Bitstrea
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
Page<BitstreamRest> page = new PageImpl<Bitstream>(bit, pageable, total).map(converter::toRest);
Projection projection = utils.obtainProjection(true);
Page<BitstreamRest> page = new PageImpl<>(bit, pageable, total)
.map((bitstream) -> converter.toRest(bitstream, projection));
return page;
}

View File

@@ -17,6 +17,7 @@ import org.dspace.app.rest.converter.BrowseEntryConverter;
import org.dspace.app.rest.converter.ConverterService;
import org.dspace.app.rest.model.BrowseEntryRest;
import org.dspace.app.rest.model.BrowseIndexRest;
import org.dspace.app.rest.projection.Projection;
import org.dspace.app.rest.utils.ScopeResolver;
import org.dspace.browse.BrowseEngine;
import org.dspace.browse.BrowseException;
@@ -55,7 +56,7 @@ public class BrowseEntryLinkRepository extends AbstractDSpaceRestRepository
// FIXME It will be nice to drive arguments binding by annotation as in normal spring controller methods
public Page<BrowseEntryRest> listBrowseEntries(HttpServletRequest request, String browseName,
Pageable pageable, String projection)
Pageable pageable, Projection projection)
throws BrowseException, SQLException {
// FIXME this should be bind automatically and available as method
// argument
@@ -122,7 +123,7 @@ public class BrowseEntryLinkRepository extends AbstractDSpaceRestRepository
binfo.getResultsPerPage());
Page<BrowseEntryRest> page = new PageImpl<>(Arrays.asList(binfo.getStringResults()), pageResultInfo,
binfo.getTotal()).map(browseEntryConverter);
BrowseIndexRest biRest = converter.toRest(bi);
BrowseIndexRest biRest = converter.toRest(bi, projection);
page.forEach(t -> t.setBrowseIndex(biRest));
return page;
}

View File

@@ -12,6 +12,7 @@ import java.util.List;
import org.dspace.app.rest.converter.ConverterService;
import org.dspace.app.rest.model.BrowseIndexRest;
import org.dspace.app.rest.projection.Projection;
import org.dspace.browse.BrowseException;
import org.dspace.browse.BrowseIndex;
import org.dspace.core.Context;
@@ -42,7 +43,7 @@ public class BrowseIndexRestRepository extends DSpaceRestRepository<BrowseIndexR
throw new RuntimeException(e.getMessage(), e);
}
if (bix != null) {
bi = converter.toRest(bix);
bi = converter.toRest(bix, utils.obtainProjection());
}
return bi;
}
@@ -61,7 +62,9 @@ public class BrowseIndexRestRepository extends DSpaceRestRepository<BrowseIndexR
} catch (BrowseException e) {
throw new RuntimeException(e.getMessage(), e);
}
Page<BrowseIndexRest> page = new PageImpl<BrowseIndex>(indexesList, pageable, total).map(converter::toRest);
Projection projection = utils.obtainProjection(true);
Page<BrowseIndexRest> page = new PageImpl<>(indexesList, pageable, total)
.map((object) -> converter.toRest(object, projection));
return page;
}

View File

@@ -14,9 +14,10 @@ import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.dspace.app.rest.converter.ItemConverter;
import org.dspace.app.rest.converter.ConverterService;
import org.dspace.app.rest.model.BrowseIndexRest;
import org.dspace.app.rest.model.ItemRest;
import org.dspace.app.rest.projection.Projection;
import org.dspace.app.rest.utils.ScopeResolver;
import org.dspace.browse.BrowseEngine;
import org.dspace.browse.BrowseException;
@@ -47,13 +48,13 @@ import org.springframework.stereotype.Component;
public class BrowseItemLinkRepository extends AbstractDSpaceRestRepository
implements LinkRestRepository {
@Autowired
ItemConverter converter;
ConverterService converter;
@Autowired
ScopeResolver scopeResolver;
public Page<ItemRest> listBrowseItems(HttpServletRequest request, String browseName, Pageable pageable,
String projection)
Projection projection)
throws BrowseException, SQLException {
//FIXME these should be bind automatically and available as method arguments
String scope = null;
@@ -151,7 +152,9 @@ public class BrowseItemLinkRepository extends AbstractDSpaceRestRepository
for (IndexableObject bb : binfo.getBrowseItemResults()) {
tmpResult.add((Item) bb);
}
Page<ItemRest> page = new PageImpl<Item>(tmpResult, pageResultInfo, binfo.getTotal()).map(converter);
Page<ItemRest> page = new PageImpl<Item>(tmpResult, pageResultInfo, binfo.getTotal())
.map((object) -> converter.toRest(object, projection));
return page;
}

View File

@@ -93,7 +93,7 @@ public class ClaimedTaskRestRepository extends DSpaceRestRepository<ClaimedTaskR
if (task == null) {
return null;
}
return converter.toRest(task);
return converter.toRest(task, utils.obtainProjection());
}
@SearchRestMethod(name = "findByUser")
@@ -118,7 +118,8 @@ public class ClaimedTaskRestRepository extends DSpaceRestRepository<ClaimedTaskR
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
Page<ClaimedTaskRest> page = utils.getPage(tasks, pageable).map(converter::toRest);
Page<ClaimedTaskRest> page = utils.getPage(tasks, pageable)
.map((object) -> converter.toRest(object, utils.obtainProjection()));
return page;
}

View File

@@ -26,6 +26,7 @@ import org.dspace.app.rest.exception.UnprocessableEntityException;
import org.dspace.app.rest.model.CollectionRest;
import org.dspace.app.rest.model.CommunityRest;
import org.dspace.app.rest.model.patch.Patch;
import org.dspace.app.rest.projection.Projection;
import org.dspace.app.rest.repository.patch.DSpaceObjectPatch;
import org.dspace.app.rest.utils.CollectionRestEqualityUtils;
import org.dspace.authorize.AuthorizeException;
@@ -80,7 +81,7 @@ public class CollectionRestRepository extends DSpaceObjectRestRepository<Collect
if (collection == null) {
return null;
}
return converter.toRest(collection);
return converter.toRest(collection, utils.obtainProjection());
}
@Override
@@ -97,7 +98,9 @@ public class CollectionRestRepository extends DSpaceObjectRestRepository<Collect
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
Page<CollectionRest> page = new PageImpl<>(collections, pageable, total).map(converter::toRest);
Projection projection = utils.obtainProjection(true);
Page<CollectionRest> page = new PageImpl<>(collections, pageable, total)
.map((object) -> converter.toRest(object, projection));
return page;
}
@@ -121,7 +124,8 @@ public class CollectionRestRepository extends DSpaceObjectRestRepository<Collect
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
Page<CollectionRest> page = utils.getPage(collections, pageable).map(converter::toRest);
Page<CollectionRest> page = utils.getPage(collections, pageable)
.map((object) -> converter.toRest(object, utils.obtainProjection()));
return page;
}
@@ -138,7 +142,8 @@ public class CollectionRestRepository extends DSpaceObjectRestRepository<Collect
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
Page<CollectionRest> page = utils.getPage(collections, pageable).map(converter::toRest);
Page<CollectionRest> page = utils.getPage(collections, pageable)
.map((object) -> converter.toRest(object, utils.obtainProjection()));
return page;
}
@@ -191,7 +196,7 @@ public class CollectionRestRepository extends DSpaceObjectRestRepository<Collect
} catch (SQLException e) {
throw new RuntimeException("Unable to create new Collection under parent Community " + id, e);
}
return converter.toRest(collection);
return converter.toRest(collection, Projection.DEFAULT);
}
@@ -210,7 +215,7 @@ public class CollectionRestRepository extends DSpaceObjectRestRepository<Collect
if (collection == null) {
throw new ResourceNotFoundException(apiCategory + "." + model + " with id: " + id + " not found");
}
CollectionRest originalCollectionRest = converter.toRest(collection);
CollectionRest originalCollectionRest = converter.toRest(collection, Projection.DEFAULT);
if (collectionRestEqualityUtils.isCollectionRestEqualWithoutMetadata(originalCollectionRest, collectionRest)) {
metadataConverter.setMetadata(context, collection, collectionRest.getMetadata());
} else {
@@ -218,7 +223,7 @@ public class CollectionRestRepository extends DSpaceObjectRestRepository<Collect
+ id + ", "
+ collectionRest.getId());
}
return converter.toRest(collection);
return converter.toRest(collection, Projection.DEFAULT);
}
@Override
@PreAuthorize("hasPermission(#id, 'COLLECTION', 'DELETE')")

View File

@@ -24,6 +24,7 @@ import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException;
import org.dspace.app.rest.exception.UnprocessableEntityException;
import org.dspace.app.rest.model.CommunityRest;
import org.dspace.app.rest.model.patch.Patch;
import org.dspace.app.rest.projection.Projection;
import org.dspace.app.rest.repository.patch.DSpaceObjectPatch;
import org.dspace.app.rest.utils.CommunityRestEqualityUtils;
import org.dspace.authorize.AuthorizeException;
@@ -80,7 +81,7 @@ public class CommunityRestRepository extends DSpaceObjectRestRepository<Communit
throw new RuntimeException(e.getMessage(), e);
}
return converter.toRest(community);
return converter.toRest(community, Projection.DEFAULT);
}
@Override
@@ -117,7 +118,7 @@ public class CommunityRestRepository extends DSpaceObjectRestRepository<Communit
throw new RuntimeException(e.getMessage(), e);
}
return converter.toRest(community);
return converter.toRest(community, Projection.DEFAULT);
}
@Override
@@ -132,7 +133,7 @@ public class CommunityRestRepository extends DSpaceObjectRestRepository<Communit
if (community == null) {
return null;
}
return converter.toRest(community);
return converter.toRest(community, utils.obtainProjection());
}
@Override
@@ -149,7 +150,9 @@ public class CommunityRestRepository extends DSpaceObjectRestRepository<Communit
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
Page<CommunityRest> page = new PageImpl<Community>(communities, pageable, total).map(converter::toRest);
Projection projection = utils.obtainProjection(true);
Page<CommunityRest> page = new PageImpl<>(communities, pageable, total)
.map((object) -> converter.toRest(object, projection));
return page;
}
@@ -163,7 +166,8 @@ public class CommunityRestRepository extends DSpaceObjectRestRepository<Communit
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
Page<CommunityRest> page = utils.getPage(topCommunities, pageable).map(converter::toRest);
Page<CommunityRest> page = utils.getPage(topCommunities, pageable)
.map((object) -> converter.toRest(object, utils.obtainProjection()));
return page;
}
@@ -184,7 +188,8 @@ public class CommunityRestRepository extends DSpaceObjectRestRepository<Communit
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
Page<CommunityRest> page = utils.getPage(subCommunities, pageable).map(converter::toRest);
Page<CommunityRest> page = utils.getPage(subCommunities, pageable)
.map((object) -> converter.toRest(object, utils.obtainProjection()));
return page;
}
@@ -215,14 +220,14 @@ public class CommunityRestRepository extends DSpaceObjectRestRepository<Communit
if (community == null) {
throw new ResourceNotFoundException(apiCategory + "." + model + " with id: " + id + " not found");
}
CommunityRest originalCommunityRest = converter.toRest(community);
CommunityRest originalCommunityRest = converter.toRest(community, Projection.DEFAULT);
if (communityRestEqualityUtils.isCommunityRestEqualWithoutMetadata(originalCommunityRest, communityRest)) {
metadataConverter.setMetadata(context, community, communityRest.getMetadata());
} else {
throw new UnprocessableEntityException("The given JSON and the original Community differ more " +
"than just the metadata");
}
return converter.toRest(community);
return converter.toRest(community, Projection.DEFAULT);
}
@Override
@PreAuthorize("hasPermission(#id, 'COMMUNITY', 'DELETE')")

View File

@@ -15,6 +15,7 @@ import org.dspace.app.rest.converter.MetadataConverter;
import org.dspace.app.rest.exception.UnprocessableEntityException;
import org.dspace.app.rest.model.DSpaceObjectRest;
import org.dspace.app.rest.model.patch.Patch;
import org.dspace.app.rest.projection.Projection;
import org.dspace.app.rest.repository.patch.DSpaceObjectPatch;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.DSpaceObject;
@@ -78,7 +79,7 @@ public abstract class DSpaceObjectRestRepository<M extends DSpaceObject, R exten
*/
protected void updateDSpaceObject(M dso, R dsoRest)
throws AuthorizeException, SQLException {
R origDsoRest = converter.toRest(dso);
R origDsoRest = converter.toRest(dso, Projection.DEFAULT);
if (!origDsoRest.getMetadata().equals(dsoRest.getMetadata())) {
metadataConverter.setMetadata(obtainContext(), dso, dsoRest.getMetadata());
}

View File

@@ -23,6 +23,7 @@ import org.dspace.app.rest.model.SearchConfigurationRest;
import org.dspace.app.rest.model.SearchResultsRest;
import org.dspace.app.rest.model.SearchSupportRest;
import org.dspace.app.rest.parameter.SearchFilter;
import org.dspace.app.rest.projection.Projection;
import org.dspace.app.rest.utils.DiscoverQueryBuilder;
import org.dspace.app.rest.utils.ScopeResolver;
import org.dspace.core.Context;
@@ -85,12 +86,13 @@ public class DiscoveryRestRepository extends AbstractDSpaceRestRepository {
DiscoveryConfiguration discoveryConfiguration = searchConfigurationService
.getDiscoveryConfigurationByNameOrDso(configuration, scopeObject);
return discoverConfigurationConverter.convert(discoveryConfiguration);
return discoverConfigurationConverter.convert(discoveryConfiguration, utils.obtainProjection());
}
public SearchResultsRest getSearchObjects(final String query, final String dsoType, final String dsoScope,
final String configuration,
final List<SearchFilter> searchFilters, final Pageable page) {
final List<SearchFilter> searchFilters, final Pageable page,
final Projection projection) {
Context context = obtainContext();
IndexableObject scopeObject = scopeResolver.resolveScope(context, dsoScope);
DiscoveryConfiguration discoveryConfiguration = searchConfigurationService
@@ -111,7 +113,7 @@ public class DiscoveryRestRepository extends AbstractDSpaceRestRepository {
return discoverResultConverter
.convert(context, query, dsoType, configuration, dsoScope, searchFilters, page, searchResult,
discoveryConfiguration);
discoveryConfiguration, projection);
}
public FacetConfigurationRest getFacetsConfiguration(final String dsoScope, final String configuration) {
@@ -150,7 +152,8 @@ public class DiscoveryRestRepository extends AbstractDSpaceRestRepository {
}
FacetResultsRest facetResultsRest = discoverFacetResultsConverter.convert(context, facetName, prefix, query,
dsoType, dsoScope, searchFilters, searchResult, discoveryConfiguration, page);
dsoType, dsoScope, searchFilters, searchResult, discoveryConfiguration, page,
utils.obtainProjection());
return facetResultsRest;
}
@@ -176,7 +179,8 @@ public class DiscoveryRestRepository extends AbstractDSpaceRestRepository {
}
SearchResultsRest searchResultsRest = discoverFacetsConverter.convert(context, query, dsoType,
configuration, dsoScope, searchFilters, page, discoveryConfiguration, searchResult);
configuration, dsoScope, searchFilters, page, discoveryConfiguration, searchResult,
utils.obtainProjection());
return searchResultsRest;

View File

@@ -22,6 +22,7 @@ import org.dspace.app.rest.exception.RESTAuthorizationException;
import org.dspace.app.rest.exception.UnprocessableEntityException;
import org.dspace.app.rest.model.EPersonRest;
import org.dspace.app.rest.model.patch.Patch;
import org.dspace.app.rest.projection.Projection;
import org.dspace.app.rest.repository.patch.EPersonPatch;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.service.AuthorizeService;
@@ -90,7 +91,7 @@ public class EPersonRestRepository extends DSpaceObjectRestRepository<EPerson, E
throw new RuntimeException(e.getMessage(), e);
}
return converter.toRest(eperson);
return converter.toRest(eperson, Projection.DEFAULT);
}
@Override
@@ -105,7 +106,7 @@ public class EPersonRestRepository extends DSpaceObjectRestRepository<EPerson, E
if (eperson == null) {
return null;
}
return converter.toRest(eperson);
return converter.toRest(eperson, utils.obtainProjection());
}
@Override
@@ -123,7 +124,9 @@ public class EPersonRestRepository extends DSpaceObjectRestRepository<EPerson, E
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
Page<EPersonRest> page = new PageImpl<>(epersons, pageable, total).map(converter::toRest);
Projection projection = utils.obtainProjection(true);
Page<EPersonRest> page = new PageImpl<>(epersons, pageable, total)
.map((object) -> converter.toRest(object, projection));
return page;
}
@@ -149,7 +152,8 @@ public class EPersonRestRepository extends DSpaceObjectRestRepository<EPerson, E
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
Page<EPersonRest> page = new PageImpl<>(epersons, pageable, total).map(converter::toRest);
Page<EPersonRest> page = new PageImpl<>(epersons, pageable, total)
.map((object) -> converter.toRest(object, utils.obtainProjection()));
return page;
}
@@ -173,7 +177,7 @@ public class EPersonRestRepository extends DSpaceObjectRestRepository<EPerson, E
if (eperson == null) {
return null;
}
return converter.toRest(eperson);
return converter.toRest(eperson, utils.obtainProjection());
}
@Override

View File

@@ -12,6 +12,7 @@ import java.util.List;
import org.dspace.app.rest.converter.ConverterService;
import org.dspace.app.rest.model.EntityTypeRest;
import org.dspace.app.rest.projection.Projection;
import org.dspace.content.EntityType;
import org.dspace.content.service.EntityTypeService;
import org.dspace.core.Context;
@@ -39,7 +40,7 @@ public class EntityTypeRestRepository extends DSpaceRestRepository<EntityTypeRes
if (entityType == null) {
throw new ResourceNotFoundException("The entityType for ID: " + integer + " could not be found");
}
return converter.toRest(entityType);
return converter.toRest(entityType, utils.obtainProjection());
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
@@ -52,7 +53,9 @@ public class EntityTypeRestRepository extends DSpaceRestRepository<EntityTypeRes
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
Page<EntityTypeRest> page = utils.getPage(entityTypeList, pageable).map(converter::toRest);
Projection projection = utils.obtainProjection(true);
Page<EntityTypeRest> page = utils.getPage(entityTypeList, pageable)
.map((object) -> converter.toRest(object, projection));
return page;
}

View File

@@ -19,6 +19,7 @@ import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException;
import org.dspace.app.rest.exception.UnprocessableEntityException;
import org.dspace.app.rest.model.GroupRest;
import org.dspace.app.rest.model.patch.Patch;
import org.dspace.app.rest.projection.Projection;
import org.dspace.app.rest.repository.patch.DSpaceObjectPatch;
import org.dspace.authorize.AuthorizeException;
import org.dspace.core.Context;
@@ -75,7 +76,7 @@ public class GroupRestRepository extends DSpaceObjectRestRepository<Group, Group
throw new RuntimeException(excSQL.getMessage(), excSQL);
}
return converter.toRest(group);
return converter.toRest(group, Projection.DEFAULT);
}
@Override
@@ -90,7 +91,7 @@ public class GroupRestRepository extends DSpaceObjectRestRepository<Group, Group
if (group == null) {
return null;
}
return converter.toRest(group);
return converter.toRest(group, utils.obtainProjection());
}
@PreAuthorize("hasAuthority('ADMIN')")
@@ -104,7 +105,9 @@ public class GroupRestRepository extends DSpaceObjectRestRepository<Group, Group
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
Page<GroupRest> page = new PageImpl<Group>(groups, pageable, total).map(converter::toRest);
Projection projection = utils.obtainProjection(true);
Page<GroupRest> page = new PageImpl<Group>(groups, pageable, total)
.map((object) -> converter.toRest(object, projection));
return page;
}

View File

@@ -13,15 +13,16 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.dspace.app.rest.converter.ConverterService;
import org.dspace.app.rest.converter.HarvestedCollectionConverter;
import org.dspace.app.rest.exception.UnprocessableEntityException;
import org.dspace.app.rest.model.HarvestTypeEnum;
import org.dspace.app.rest.model.HarvestedCollectionRest;
import org.dspace.app.rest.projection.Projection;
import org.dspace.content.Collection;
import org.dspace.core.Context;
import org.dspace.harvest.HarvestedCollection;
@@ -45,6 +46,9 @@ public class HarvestedCollectionRestRepository extends AbstractDSpaceRestReposit
@Autowired
HarvestedCollectionConverter harvestedCollectionConverter;
@Autowired
ConverterService converter;
public HarvestedCollectionRest findOne(Collection collection) throws SQLException {
Context context = obtainContext();
@@ -54,7 +58,8 @@ public class HarvestedCollectionRestRepository extends AbstractDSpaceRestReposit
HarvestedCollection harvestedCollection = harvestedCollectionService.find(context, collection);
List<Map<String,String>> configs = OAIHarvester.getAvailableMetadataFormats();
return harvestedCollectionConverter.fromModel(harvestedCollection, collection, configs);
return harvestedCollectionConverter.fromModel(harvestedCollection, collection, configs,
utils.obtainProjection());
}
/**
@@ -75,7 +80,7 @@ public class HarvestedCollectionRestRepository extends AbstractDSpaceRestReposit
if (harvestedCollectionRest.getHarvestType() == HarvestTypeEnum.NONE.getValue()
&& harvestedCollection != null) {
harvestedCollectionService.delete(context, harvestedCollection);
return harvestedCollectionConverter.convert(null);
return harvestedCollectionConverter.convert(null, utils.obtainProjection());
} else if (harvestedCollectionRest.getHarvestType() != HarvestTypeEnum.NONE.getValue()) {
List<String> errors = testHarvestSettings(harvestedCollectionRest);
@@ -89,7 +94,8 @@ public class HarvestedCollectionRestRepository extends AbstractDSpaceRestReposit
harvestedCollection = harvestedCollectionService.find(context, collection);
List<Map<String,String>> configs = OAIHarvester.getAvailableMetadataFormats();
return harvestedCollectionConverter.fromModel(harvestedCollection, collection, configs);
return harvestedCollectionConverter.fromModel(harvestedCollection, collection, configs,
Projection.DEFAULT);
} else {
throw new UnprocessableEntityException(
"Incorrect harvest settings in request. The following errors were found: " + errors.toString()
@@ -147,7 +153,6 @@ public class HarvestedCollectionRestRepository extends AbstractDSpaceRestReposit
/**
* Function used to verify that the harvest settings work
* @param collection The collection to which the harvest settings should be aplied
* @param harvestedCollectionRest A object containg the harvest settings to be tested
* @return
*/

View File

@@ -16,6 +16,7 @@ import javax.servlet.http.HttpServletRequest;
import org.dspace.app.rest.converter.ConverterService;
import org.dspace.app.rest.model.ItemRest;
import org.dspace.app.rest.model.RelationshipRest;
import org.dspace.app.rest.projection.Projection;
import org.dspace.content.Item;
import org.dspace.content.Relationship;
import org.dspace.content.service.ItemService;
@@ -48,7 +49,7 @@ public class ItemRelationshipLinkRepository extends AbstractDSpaceRestRepository
public Page<RelationshipRest> getItemRelationships(@Nullable HttpServletRequest request,
UUID itemId,
@Nullable Pageable optionalPageable,
@Nullable String projection) {
Projection projection) {
try {
Context context = obtainContext();
Item item = itemService.find(context, itemId);
@@ -60,7 +61,8 @@ public class ItemRelationshipLinkRepository extends AbstractDSpaceRestRepository
Integer offset = pageable == null ? null : pageable.getOffset();
int total = relationshipService.countByItem(context, item);
List<Relationship> relationships = relationshipService.findByItem(context, item, limit, offset);
return new PageImpl<>(relationships, pageable, total).map(converter::toRest);
return new PageImpl<>(relationships, pageable, total)
.map((object) -> converter.toRest(object, projection));
} catch (SQLException e) {
throw new RuntimeException(e);
}

View File

@@ -26,7 +26,7 @@ import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException;
import org.dspace.app.rest.exception.UnprocessableEntityException;
import org.dspace.app.rest.model.ItemRest;
import org.dspace.app.rest.model.patch.Patch;
import org.dspace.app.rest.projection.ListProjection;
import org.dspace.app.rest.projection.Projection;
import org.dspace.app.rest.repository.patch.ItemPatch;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Collection;
@@ -94,7 +94,7 @@ public class ItemRestRepository extends DSpaceObjectRestRepository<Item, ItemRes
if (item == null) {
return null;
}
return converter.toRest(item);
return converter.toRest(item, utils.obtainProjection());
}
@Override
@@ -113,7 +113,8 @@ public class ItemRestRepository extends DSpaceObjectRestRepository<Item, ItemRes
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
return new PageImpl<>(items, pageable, total).map((item) -> converter.toRest(item, ListProjection.NAME));
Projection projection = utils.obtainProjection(true);
return new PageImpl<>(items, pageable, total).map((object) -> converter.toRest(object, projection));
}
@Override
@@ -208,7 +209,7 @@ public class ItemRestRepository extends DSpaceObjectRestRepository<Item, ItemRes
Item itemToReturn = installItemService.installItem(context, workspaceItem);
return converter.toRest(itemToReturn);
return converter.toRest(itemToReturn, Projection.DEFAULT);
}
@Override
@@ -237,6 +238,6 @@ public class ItemRestRepository extends DSpaceObjectRestRepository<Item, ItemRes
+ uuid + ", "
+ itemRest.getId());
}
return converter.toRest(item);
return converter.toRest(item, Projection.DEFAULT);
}
}

View File

@@ -13,6 +13,7 @@ import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.dspace.app.rest.model.CollectionRest;
import org.dspace.app.rest.model.LicenseRest;
import org.dspace.app.rest.projection.Projection;
import org.dspace.content.Collection;
import org.dspace.content.service.CollectionService;
import org.dspace.core.Context;
@@ -38,7 +39,8 @@ public class LicenseRestLinkRepository extends AbstractDSpaceRestRepository
LicenseService licenseService;
@PreAuthorize("hasAuthority('AUTHENTICATED')")
public LicenseRest getLicenseCollection(HttpServletRequest request, UUID uuid, Pageable pageable, String projection)
public LicenseRest getLicenseCollection(HttpServletRequest request, UUID uuid, Pageable pageable,
Projection projection)
throws Exception {
Context context = obtainContext();
Collection collection = collectionService.find(context, uuid);

View File

@@ -25,6 +25,7 @@ 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.MetadataFieldRest;
import org.dspace.app.rest.projection.Projection;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.MetadataField;
import org.dspace.content.MetadataSchema;
@@ -70,7 +71,7 @@ public class MetadataFieldRestRepository extends DSpaceRestRepository<MetadataFi
if (metadataField == null) {
return null;
}
return converter.toRest(metadataField);
return converter.toRest(metadataField, utils.obtainProjection());
}
@Override
@@ -81,7 +82,9 @@ public class MetadataFieldRestRepository extends DSpaceRestRepository<MetadataFi
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
Page<MetadataFieldRest> page = utils.getPage(metadataField, pageable).map(converter::toRest);
Projection projection = utils.obtainProjection(true);
Page<MetadataFieldRest> page = utils.getPage(metadataField, pageable)
.map((object) -> converter.toRest(object, projection));
return page;
}
@@ -99,7 +102,9 @@ public class MetadataFieldRestRepository extends DSpaceRestRepository<MetadataFi
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
Page<MetadataFieldRest> page = utils.getPage(metadataFields, pageable).map(converter::toRest);
Projection projection = utils.obtainProjection(true);
Page<MetadataFieldRest> page = utils.getPage(metadataFields, pageable)
.map((object) -> converter.toRest(object, projection));
return page;
}
@@ -157,7 +162,7 @@ public class MetadataFieldRestRepository extends DSpaceRestRepository<MetadataFi
}
// return
return converter.toRest(metadataField);
return converter.toRest(metadataField, Projection.DEFAULT);
}
@Override
@@ -213,6 +218,6 @@ public class MetadataFieldRestRepository extends DSpaceRestRepository<MetadataFi
throw new RuntimeException(e);
}
return converter.toRest(metadataField);
return converter.toRest(metadataField, Projection.DEFAULT);
}
}

View File

@@ -22,6 +22,7 @@ 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.MetadataSchemaRest;
import org.dspace.app.rest.projection.Projection;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.MetadataSchema;
import org.dspace.content.NonUniqueMetadataException;
@@ -62,7 +63,7 @@ public class MetadataSchemaRestRepository extends DSpaceRestRepository<MetadataS
if (metadataSchema == null) {
return null;
}
return converter.toRest(metadataSchema);
return converter.toRest(metadataSchema, utils.obtainProjection());
}
@Override
@@ -73,7 +74,9 @@ public class MetadataSchemaRestRepository extends DSpaceRestRepository<MetadataS
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
Page<MetadataSchemaRest> page = utils.getPage(metadataSchema, pageable).map(converter::toRest);
Projection projection = utils.obtainProjection(true);
Page<MetadataSchemaRest> page = utils.getPage(metadataSchema, pageable)
.map((object) -> converter.toRest(object, projection));
return page;
}
@@ -119,7 +122,7 @@ public class MetadataSchemaRestRepository extends DSpaceRestRepository<MetadataS
}
// return
return converter.toRest(metadataSchema);
return converter.toRest(metadataSchema, Projection.DEFAULT);
}
@Override
@@ -175,6 +178,6 @@ public class MetadataSchemaRestRepository extends DSpaceRestRepository<MetadataS
+ metadataSchemaRest.getPrefix() + "." + metadataSchemaRest.getNamespace() + " already exists");
}
return converter.toRest(metadataSchema);
return converter.toRest(metadataSchema, Projection.DEFAULT);
}
}

View File

@@ -21,6 +21,7 @@ import org.dspace.app.rest.converter.ConverterService;
import org.dspace.app.rest.exception.RESTAuthorizationException;
import org.dspace.app.rest.exception.UnprocessableEntityException;
import org.dspace.app.rest.model.PoolTaskRest;
import org.dspace.app.rest.projection.Projection;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.content.service.ItemService;
@@ -88,7 +89,7 @@ public class PoolTaskRestRepository extends DSpaceRestRepository<PoolTaskRest, I
if (task == null) {
return null;
}
return converter.toRest(task);
return converter.toRest(task, utils.obtainProjection());
}
@SearchRestMethod(name = "findByUser")
@@ -114,7 +115,9 @@ public class PoolTaskRestRepository extends DSpaceRestRepository<PoolTaskRest, I
} catch (SQLException | IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
Page<PoolTaskRest> page = utils.getPage(tasks, pageable).map(converter::toRest);
Projection projection = utils.obtainProjection(true);
Page<PoolTaskRest> page = utils.getPage(tasks, pageable)
.map((object) -> converter.toRest(object, projection));
return page;
}

View File

@@ -24,6 +24,7 @@ import org.dspace.app.rest.converter.ConverterService;
import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException;
import org.dspace.app.rest.exception.UnprocessableEntityException;
import org.dspace.app.rest.model.RelationshipRest;
import org.dspace.app.rest.projection.Projection;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.content.DSpaceObject;
@@ -71,7 +72,7 @@ public class RelationshipRestRepository extends DSpaceRestRepository<Relationshi
@Override
public RelationshipRest findOne(Context context, Integer integer) {
try {
return converter.toRest(relationshipService.find(context, integer));
return converter.toRest(relationshipService.find(context, integer), utils.obtainProjection());
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
@@ -88,7 +89,9 @@ public class RelationshipRestRepository extends DSpaceRestRepository<Relationshi
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
Page<RelationshipRest> page = new PageImpl<>(relationships, pageable, total).map(converter::toRest);
Projection projection = utils.obtainProjection(true);
Page<RelationshipRest> page = new PageImpl<>(relationships, pageable, total)
.map((object) -> converter.toRest(object, projection));
return page;
}
@@ -126,7 +129,7 @@ public class RelationshipRestRepository extends DSpaceRestRepository<Relationshi
relationshipService.updateItem(context, relationship.getLeftItem());
relationshipService.updateItem(context, relationship.getRightItem());
context.restoreAuthSystemState();
return converter.toRest(relationship);
return converter.toRest(relationship, Projection.DEFAULT);
} else {
throw new AccessDeniedException("You do not have write rights on this relationship's items");
}
@@ -191,7 +194,7 @@ public class RelationshipRestRepository extends DSpaceRestRepository<Relationshi
throw new AccessDeniedException("You do not have write rights on this relationship's items");
}
return converter.toRest(relationship);
return converter.toRest(relationship, Projection.DEFAULT);
} else {
throw new AccessDeniedException("You do not have write rights on this relationship's items");
}
@@ -255,7 +258,7 @@ public class RelationshipRestRepository extends DSpaceRestRepository<Relationshi
context.commit();
context.reloadEntity(relationship);
return converter.toRest(relationship);
return converter.toRest(relationship, Projection.DEFAULT);
} catch (AuthorizeException e) {
throw new AccessDeniedException("You do not have write rights on this relationship's metadata");
}
@@ -340,7 +343,9 @@ public class RelationshipRestRepository extends DSpaceRestRepository<Relationshi
}
}
Page<RelationshipRest> page = new PageImpl<>(relationships, pageable, total).map(converter::toRest);
Projection projection = utils.obtainProjection(true);
Page<RelationshipRest> page = new PageImpl<>(relationships, pageable, total)
.map((object) -> converter.toRest(object, projection));
return page;
}

View File

@@ -12,6 +12,7 @@ import java.util.List;
import org.dspace.app.rest.converter.ConverterService;
import org.dspace.app.rest.model.RelationshipTypeRest;
import org.dspace.app.rest.projection.Projection;
import org.dspace.content.RelationshipType;
import org.dspace.content.service.RelationshipTypeService;
import org.dspace.core.Context;
@@ -35,7 +36,7 @@ public class RelationshipTypeRestRepository extends DSpaceRestRepository<Relatio
@Override
public RelationshipTypeRest findOne(Context context, Integer integer) {
try {
return converter.toRest(relationshipTypeService.find(context, integer));
return converter.toRest(relationshipTypeService.find(context, integer), utils.obtainProjection());
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
@@ -49,7 +50,9 @@ public class RelationshipTypeRestRepository extends DSpaceRestRepository<Relatio
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
Page<RelationshipTypeRest> page = utils.getPage(relationshipTypeList, pageable).map(converter::toRest);
Projection projection = utils.obtainProjection(true);
Page<RelationshipTypeRest> page = utils.getPage(relationshipTypeList, pageable)
.map((object) -> converter.toRest(object, projection));
return page;
}

View File

@@ -51,7 +51,7 @@ public class ResourcePolicyRestRepository extends DSpaceRestRepository<ResourceP
if (source == null) {
return null;
}
return converter.toRest(source);
return converter.toRest(source, utils.obtainProjection());
}
@PreAuthorize("hasAuthority('AUTHENTICATED')")

View File

@@ -15,6 +15,7 @@ import javax.servlet.http.HttpServletRequest;
import org.dspace.app.rest.model.SiteRest;
import org.dspace.app.rest.model.patch.Patch;
import org.dspace.app.rest.projection.Projection;
import org.dspace.app.rest.repository.patch.DSpaceObjectPatch;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Site;
@@ -55,7 +56,7 @@ public class SiteRestRepository extends DSpaceObjectRestRepository<Site, SiteRes
if (site == null) {
return null;
}
return converter.toRest(site);
return converter.toRest(site, utils.obtainProjection());
}
@Override
@@ -67,7 +68,9 @@ public class SiteRestRepository extends DSpaceObjectRestRepository<Site, SiteRes
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
Page<SiteRest> page = new PageImpl<Site>(sites, pageable, total).map(converter::toRest);
Projection projection = utils.obtainProjection(true);
Page<SiteRest> page = new PageImpl<Site>(sites, pageable, total)
.map((object) -> converter.toRest(object, projection));
return page;
}

View File

@@ -15,6 +15,7 @@ import org.dspace.app.rest.Parameter;
import org.dspace.app.rest.SearchRestMethod;
import org.dspace.app.rest.converter.ConverterService;
import org.dspace.app.rest.model.SubmissionDefinitionRest;
import org.dspace.app.rest.projection.Projection;
import org.dspace.app.util.SubmissionConfig;
import org.dspace.app.util.SubmissionConfigReader;
import org.dspace.app.util.SubmissionConfigReaderException;
@@ -54,7 +55,7 @@ public class SubmissionDefinitionRestRepository extends DSpaceRestRepository<Sub
if (subConfig == null) {
return null;
}
return converter.toRest(subConfig);
return converter.toRest(subConfig, utils.obtainProjection());
}
@PreAuthorize("hasAuthority('AUTHENTICATED')")
@@ -63,7 +64,9 @@ public class SubmissionDefinitionRestRepository extends DSpaceRestRepository<Sub
int total = submissionConfigReader.countSubmissionConfigs();
List<SubmissionConfig> subConfs = submissionConfigReader.getAllSubmissionConfigs(
pageable.getPageSize(), pageable.getOffset());
Page<SubmissionDefinitionRest> page = new PageImpl<>(subConfs, pageable, total).map(converter::toRest);
Projection projection = utils.obtainProjection(true);
Page<SubmissionDefinitionRest> page = new PageImpl<>(subConfs, pageable, total)
.map((object) -> converter.toRest(object, projection));
return page;
}
@@ -76,7 +79,8 @@ public class SubmissionDefinitionRestRepository extends DSpaceRestRepository<Sub
return null;
}
SubmissionDefinitionRest def = converter
.toRest(submissionConfigReader.getSubmissionConfigByCollection(col.getHandle()));
.toRest(submissionConfigReader.getSubmissionConfigByCollection(col.getHandle()),
utils.obtainProjection());
return def;
}

View File

@@ -12,6 +12,7 @@ import java.util.List;
import org.dspace.app.rest.converter.ConverterService;
import org.dspace.app.rest.model.SubmissionFormRest;
import org.dspace.app.rest.projection.Projection;
import org.dspace.app.util.DCInputSet;
import org.dspace.app.util.DCInputsReader;
import org.dspace.app.util.DCInputsReaderException;
@@ -53,7 +54,7 @@ public class SubmissionFormRestRepository extends DSpaceRestRepository<Submissio
if (inputConfig == null) {
return null;
}
return converter.toRest(inputConfig);
return converter.toRest(inputConfig, utils.obtainProjection());
}
@PreAuthorize("hasAuthority('AUTHENTICATED')")
@@ -66,7 +67,9 @@ public class SubmissionFormRestRepository extends DSpaceRestRepository<Submissio
} catch (DCInputsReaderException e) {
throw new IllegalStateException(e.getMessage(), e);
}
Page<SubmissionFormRest> page = new PageImpl<>(subConfs, pageable, total).map(converter::toRest);
Projection projection = utils.obtainProjection(true);
Page<SubmissionFormRest> page = new PageImpl<>(subConfs, pageable, total)
.map((object) -> converter.toRest(object, projection));
return page;
}

View File

@@ -13,6 +13,7 @@ import java.util.List;
import org.dspace.app.rest.converter.ConverterService;
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.util.SubmissionConfig;
import org.dspace.app.util.SubmissionConfigReader;
import org.dspace.app.util.SubmissionConfigReaderException;
@@ -47,7 +48,7 @@ public class SubmissionPanelRestRepository extends DSpaceRestRepository<Submissi
public SubmissionSectionRest findOne(Context context, String id) {
try {
SubmissionStepConfig step = submissionConfigReader.getStepConfig(id);
return converter.toRest(step);
return converter.toRest(step, utils.obtainProjection());
} catch (SubmissionConfigReaderException e) {
//TODO wrap with a specific exception
throw new RuntimeException(e.getMessage(), e);
@@ -68,7 +69,9 @@ public class SubmissionPanelRestRepository extends DSpaceRestRepository<Submissi
stepConfs.add(step);
}
}
Page<SubmissionSectionRest> page = new PageImpl<>(stepConfs, pageable, total).map(converter::toRest);
Projection projection = utils.obtainProjection(true);
Page<SubmissionSectionRest> page = new PageImpl<>(stepConfs, pageable, total)
.map((object) -> converter.toRest(object, projection));
return page;
}

View File

@@ -12,8 +12,10 @@ import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Logger;
import org.dspace.app.rest.converter.ConverterService;
import org.dspace.app.rest.model.AccessConditionOptionRest;
import org.dspace.app.rest.model.SubmissionUploadRest;
import org.dspace.app.rest.projection.Projection;
import org.dspace.app.rest.utils.DateMathParser;
import org.dspace.app.util.SubmissionConfig;
import org.dspace.app.util.SubmissionConfigReader;
@@ -56,6 +58,9 @@ public class SubmissionUploadRestRepository extends DSpaceRestRepository<Submiss
@Autowired
GroupService groupService;
@Autowired
ConverterService converter;
DateMathParser dateMathParser = new DateMathParser();
public SubmissionUploadRestRepository() throws SubmissionConfigReaderException {
@@ -67,7 +72,7 @@ public class SubmissionUploadRestRepository extends DSpaceRestRepository<Submiss
public SubmissionUploadRest findOne(Context context, String submitName) {
UploadConfiguration config = uploadConfigurationService.getMap().get(submitName);
try {
return convert(context, config);
return convert(context, config, utils.obtainProjection());
} catch (Exception e) {
log.error(e.getMessage(), e);
}
@@ -79,6 +84,7 @@ public class SubmissionUploadRestRepository extends DSpaceRestRepository<Submiss
public Page<SubmissionUploadRest> findAll(Context context, Pageable pageable) {
List<SubmissionConfig> subConfs = new ArrayList<SubmissionConfig>();
subConfs = submissionConfigReader.getAllSubmissionConfigs(pageable.getPageSize(), pageable.getOffset());
Projection projection = utils.obtainProjection(true);
List<SubmissionUploadRest> results = new ArrayList<>();
for (SubmissionConfig config : subConfs) {
for (int i = 0; i < config.getNumberOfSteps(); i++) {
@@ -87,7 +93,7 @@ public class SubmissionUploadRestRepository extends DSpaceRestRepository<Submiss
UploadConfiguration uploadConfig = uploadConfigurationService.getMap().get(step.getId());
if (uploadConfig != null) {
try {
results.add(convert(context, uploadConfig));
results.add(convert(context, uploadConfig, projection));
} catch (Exception e) {
log.error(e.getMessage(), e);
}
@@ -103,8 +109,10 @@ public class SubmissionUploadRestRepository extends DSpaceRestRepository<Submiss
return SubmissionUploadRest.class;
}
private SubmissionUploadRest convert(Context context, UploadConfiguration config) throws Exception {
private SubmissionUploadRest convert(Context context, UploadConfiguration config, Projection projection)
throws Exception {
SubmissionUploadRest result = new SubmissionUploadRest();
result.setProjection(projection);
for (AccessConditionOption option : config.getOptions()) {
AccessConditionOptionRest optionRest = new AccessConditionOptionRest();
if (option.getGroupName() != null) {

Some files were not shown because too many files have changed in this diff Show More