DS-3489: Added HAL link factories for AuthorityEntryResource and SubmissionSectionResource

This commit is contained in:
Tom Desair
2017-11-20 16:48:27 +01:00
committed by Tom Desair
parent f9041df1c8
commit a0433f72ef
15 changed files with 152 additions and 62 deletions

View File

@@ -1219,7 +1219,7 @@ prevent the generation of resource policy entry values with null dspace_object a
@Override
protected void getAuthoritiesAndConfidences(String fieldKey, Collection collection, List<String> values, List<String> authorities, List<Integer> confidences, int i) {
Choices c = choiceAuthorityService.getBestMatch(fieldKey, values.get(i), collection, null);
authorities.add(c.values.length > 0 ? c.values[0].authority : null);
authorities.add(c.values.length > 0 && c.values[0] != null ? c.values[0].authority : null);
confidences.add(c.confidence);
}

View File

@@ -0,0 +1,56 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest.link;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import java.util.LinkedList;
import org.atteo.evo.inflector.English;
import org.dspace.app.rest.RestResourceController;
import org.dspace.app.rest.model.AuthorityEntryRest;
import org.dspace.app.rest.model.AuthorityRest;
import org.dspace.app.rest.model.hateoas.AuthorityEntryResource;
import org.dspace.app.rest.utils.AuthorityUtils;
import org.springframework.data.domain.Pageable;
import org.springframework.hateoas.Link;
import org.springframework.stereotype.Component;
import org.springframework.web.util.UriComponentsBuilder;
/**
* This class' purpose is to provide a factory to add links to the AuthorityEntryResource. The addLinks factory will be called
* from the HalLinkService class addLinks method.
*/
@Component
public class AuthorityEntryHalLinkFactory extends HalLinkFactory<AuthorityEntryResource, RestResourceController> {
protected void addLinks(final AuthorityEntryResource halResource, final Pageable pageable, final LinkedList<Link> list) throws Exception{
AuthorityEntryRest entry = halResource.getContent();
if (entry.getOtherInformation() != null) {
if (entry.getOtherInformation().containsKey(AuthorityUtils.RESERVED_KEYMAP_PARENT)) {
UriComponentsBuilder uriComponentsBuilder = linkTo(getMethodOn(AuthorityRest.CATEGORY, AuthorityRest.NAME)
.findRel(null, AuthorityRest.CATEGORY,
English.plural(AuthorityRest.NAME), entry.getAuthorityName() + "/" + AuthorityRest.ENTRY,
entry.getOtherInformation().get(AuthorityUtils.RESERVED_KEYMAP_PARENT), null, null, null)).toUriComponentsBuilder();
list.add(buildLink(uriComponentsBuilder.build().toString(), AuthorityUtils.RESERVED_KEYMAP_PARENT));
}
}
}
protected Class<RestResourceController> getControllerClass() {
return RestResourceController.class;
}
protected Class<AuthorityEntryResource> getResourceClass() {
return AuthorityEntryResource.class;
}
}

View File

@@ -0,0 +1,55 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest.link;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import java.util.LinkedList;
import org.atteo.evo.inflector.English;
import org.dspace.app.rest.RestResourceController;
import org.dspace.app.rest.model.SubmissionFormRest;
import org.dspace.app.rest.model.SubmissionSectionRest;
import org.dspace.app.rest.model.hateoas.SubmissionSectionResource;
import org.dspace.app.util.SubmissionStepConfig;
import org.springframework.data.domain.Pageable;
import org.springframework.hateoas.Link;
import org.springframework.stereotype.Component;
import org.springframework.web.util.UriComponentsBuilder;
/**
* This class' purpose is to provide a factory to add links to the AuthorityEntryResource. The addLinks factory will be called
* from the HalLinkService class addLinks method.
*/
@Component
public class SubmissionSectionHalLinkFactory extends HalLinkFactory<SubmissionSectionResource, RestResourceController> {
protected void addLinks(final SubmissionSectionResource halResource, final Pageable pageable, final LinkedList<Link> list) throws Exception{
SubmissionSectionRest sd = halResource.getContent();
if(SubmissionStepConfig.INPUT_FORM_STEP_NAME.equals(sd.getSectionType())) {
UriComponentsBuilder uriComponentsBuilder = linkTo(getMethodOn(SubmissionFormRest.CATEGORY, SubmissionFormRest.NAME)
.findRel(null, SubmissionFormRest.CATEGORY, English.plural(SubmissionFormRest.NAME), sd.getId(), "", null, null, null))
.toUriComponentsBuilder();
String uribuilder = uriComponentsBuilder.build().toString();
list.add(buildLink(uribuilder.substring(0, uribuilder.lastIndexOf("/")), SubmissionFormRest.NAME_LINK_ON_PANEL));
}
}
protected Class<RestResourceController> getControllerClass() {
return RestResourceController.class;
}
protected Class<SubmissionSectionResource> getResourceClass() {
return SubmissionSectionResource.class;
}
}

View File

@@ -22,6 +22,8 @@ public interface RestModel extends Serializable {
public static final String EPERSON = "eperson";
public static final String DISCOVER = "discover";
public static final String ROOT = "root";
public static final String CONFIGURATION = "config";
public static final String INTEGRATION = "integration";
@JsonIgnore
public String getCategory();

View File

@@ -7,20 +7,8 @@
*/
package org.dspace.app.rest.model.hateoas;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import org.atteo.evo.inflector.English;
import org.dspace.app.rest.RestResourceController;
import org.dspace.app.rest.model.AuthorityEntryRest;
import org.dspace.app.rest.model.AuthorityRest;
import org.dspace.app.rest.model.hateoas.annotations.RelNameDSpaceResource;
import org.dspace.app.rest.utils.AuthorityUtils;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.ResourceSupport;
import org.springframework.web.util.UriComponentsBuilder;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
/**
* Authority Rest HAL Resource. The HAL Resource wraps the REST Resource adding
@@ -30,28 +18,10 @@ import com.fasterxml.jackson.annotation.JsonUnwrapped;
*
*/
@RelNameDSpaceResource(AuthorityEntryRest.NAME)
public class AuthorityEntryResource extends ResourceSupport {
public class AuthorityEntryResource extends HALResource<AuthorityEntryRest> {
@JsonUnwrapped
private final AuthorityEntryRest data;
public AuthorityEntryResource(AuthorityEntryRest entry) {
this.data = entry;
if (entry.getOtherInformation() != null) {
if (entry.getOtherInformation().containsKey(AuthorityUtils.RESERVED_KEYMAP_PARENT)) {
RestResourceController methodOn = methodOn(RestResourceController.class, AuthorityRest.CATEGORY,
AuthorityRest.NAME);
UriComponentsBuilder uriComponentsBuilder = linkTo(methodOn.findRel(null, AuthorityRest.CATEGORY,
English.plural(AuthorityRest.NAME), entry.getAuthorityName() + "/" + AuthorityRest.ENTRY,
entry.getOtherInformation().get(AuthorityUtils.RESERVED_KEYMAP_PARENT), null, null, null)).toUriComponentsBuilder();
Link link = new Link(uriComponentsBuilder.build().toString(), AuthorityUtils.RESERVED_KEYMAP_PARENT);
add(link);
}
}
super(entry);
}
public AuthorityEntryRest getData() {
return data;
}
}

View File

@@ -8,6 +8,7 @@
package org.dspace.app.rest.model.hateoas;
import org.dspace.app.rest.model.BrowseEntryRest;
import org.dspace.app.rest.model.hateoas.annotations.RelNameDSpaceResource;
/**
* Browse Entry Rest HAL Resource. The HAL Resource wraps the REST Resource

View File

@@ -8,6 +8,7 @@
package org.dspace.app.rest.model.hateoas;
import org.dspace.app.rest.model.SearchConfigurationRest;
import org.dspace.app.rest.model.hateoas.annotations.RelNameDSpaceResource;
/**
* This class serves as a wrapper class to wrap the SearchConfigurationRest into a HAL resource

View File

@@ -15,6 +15,7 @@ import org.apache.commons.collections4.CollectionUtils;
import org.dspace.app.rest.model.SearchFacetEntryRest;
import org.dspace.app.rest.model.SearchResultEntryRest;
import org.dspace.app.rest.model.SearchResultsRest;
import org.dspace.app.rest.model.hateoas.annotations.RelNameDSpaceResource;
import org.dspace.app.rest.utils.Utils;
/**

View File

@@ -8,6 +8,7 @@
package org.dspace.app.rest.model.hateoas;
import org.dspace.app.rest.model.SearchSupportRest;
import org.dspace.app.rest.model.hateoas.annotations.RelNameDSpaceResource;
/**
* This class' purpose is to wrap the SearchSupportRest into a HAL resource

View File

@@ -7,18 +7,9 @@
*/
package org.dspace.app.rest.model.hateoas;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import org.atteo.evo.inflector.English;
import org.dspace.app.rest.RestResourceController;
import org.dspace.app.rest.model.SubmissionFormRest;
import org.dspace.app.rest.model.SubmissionSectionRest;
import org.dspace.app.rest.model.hateoas.annotations.RelNameDSpaceResource;
import org.dspace.app.rest.utils.Utils;
import org.dspace.app.util.SubmissionStepConfig;
import org.springframework.hateoas.Link;
import org.springframework.web.util.UriComponentsBuilder;
/**
* SubmissionPanel Rest HAL Resource. The HAL Resource wraps the REST Resource
@@ -32,14 +23,5 @@ public class SubmissionSectionResource extends DSpaceResource<SubmissionSectionR
public SubmissionSectionResource(SubmissionSectionRest sd, Utils utils, String... rels) {
super(sd, utils, rels);
if(SubmissionStepConfig.INPUT_FORM_STEP_NAME.equals(sd.getSectionType())) {
RestResourceController methodOn = methodOn(RestResourceController.class, SubmissionFormRest.CATEGORY, SubmissionFormRest.NAME);
UriComponentsBuilder uriComponentsBuilder = linkTo(methodOn
.findRel(null, SubmissionFormRest.CATEGORY, English.plural(SubmissionFormRest.NAME), sd.getId(), "", null, null, null))
.toUriComponentsBuilder();
String uribuilder = uriComponentsBuilder.build().toString();
Link link = new Link(uribuilder.substring(0, uribuilder.lastIndexOf("/")), SubmissionFormRest.NAME_LINK_ON_PANEL);
add(link);
}
}
}

View File

@@ -19,6 +19,7 @@ import org.dspace.app.rest.converter.AuthorityEntryRestConverter;
import org.dspace.app.rest.model.AuthorityEntryRest;
import org.dspace.app.rest.model.AuthorityRest;
import org.dspace.app.rest.model.hateoas.AuthorityEntryResource;
import org.dspace.app.rest.model.hateoas.HALResource;
import org.dspace.app.rest.utils.AuthorityUtils;
import org.dspace.content.Collection;
import org.dspace.content.authority.Choice;
@@ -53,7 +54,7 @@ public class AuthorityEntryLinkRepository extends AbstractDSpaceRestRepository
private AuthorityUtils authorityUtils;
@Override
public ResourceSupport wrapResource(AuthorityEntryRest model, String... rels) {
public HALResource wrapResource(AuthorityEntryRest model, String... rels) {
return new AuthorityEntryResource(model);
}

View File

@@ -13,6 +13,7 @@ import org.dspace.app.rest.converter.AuthorityEntryRestConverter;
import org.dspace.app.rest.model.AuthorityEntryRest;
import org.dspace.app.rest.model.AuthorityRest;
import org.dspace.app.rest.model.hateoas.AuthorityEntryResource;
import org.dspace.app.rest.model.hateoas.HALResource;
import org.dspace.app.rest.utils.AuthorityUtils;
import org.dspace.content.authority.Choice;
import org.dspace.content.authority.ChoiceAuthority;
@@ -40,7 +41,7 @@ public class AuthorityEntryValueLinkRepository extends AbstractDSpaceRestReposit
private AuthorityUtils authorityUtils;
@Override
public ResourceSupport wrapResource(AuthorityEntryRest model, String... rels) {
public HALResource wrapResource(AuthorityEntryRest model, String... rels) {
return new AuthorityEntryResource(model);
}

View File

@@ -12,6 +12,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.dspace.app.rest.SearchRestMethod;
import org.dspace.app.rest.converter.CollectionConverter;
import org.dspace.app.rest.model.CollectionRest;
import org.dspace.app.rest.model.hateoas.CollectionResource;

View File

@@ -12,10 +12,23 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.io.InputStream;
import java.util.UUID;
import org.apache.commons.codec.CharEncoding;
import org.apache.commons.io.IOUtils;
import org.dspace.app.rest.builder.*;
import org.dspace.app.rest.matcher.*;
import org.dspace.app.rest.builder.BitstreamBuilder;
import org.dspace.app.rest.builder.CollectionBuilder;
import org.dspace.app.rest.builder.CommunityBuilder;
import org.dspace.app.rest.builder.GroupBuilder;
import org.dspace.app.rest.builder.ItemBuilder;
import org.dspace.app.rest.matcher.AppliedFilterMatcher;
import org.dspace.app.rest.matcher.FacetEntryMatcher;
import org.dspace.app.rest.matcher.FacetValueMatcher;
import org.dspace.app.rest.matcher.PageMatcher;
import org.dspace.app.rest.matcher.SearchFilterMatcher;
import org.dspace.app.rest.matcher.SearchResultMatcher;
import org.dspace.app.rest.matcher.SortOptionMatcher;
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
import org.dspace.content.Bitstream;
import org.dspace.content.Collection;
@@ -26,9 +39,6 @@ import org.hamcrest.Matchers;
import org.junit.Ignore;
import org.junit.Test;
import java.io.InputStream;
import java.util.UUID;
public class DiscoveryRestControllerIT extends AbstractControllerIntegrationTest {
@@ -906,7 +916,6 @@ public class DiscoveryRestControllerIT extends AbstractControllerIntegrationTest
.withSubject("f").withSubject("g")
.withSubject("h").withSubject("i")
.withSubject("j").withSubject("k")
.build();
Item publicItem2 = new ItemBuilder().createItem(context, col2)

View File

@@ -12,7 +12,16 @@ import org.dspace.authorize.factory.AuthorizeServiceFactory;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.authorize.service.ResourcePolicyService;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.*;
import org.dspace.content.service.BitstreamFormatService;
import org.dspace.content.service.BitstreamService;
import org.dspace.content.service.BundleService;
import org.dspace.content.service.CollectionService;
import org.dspace.content.service.CommunityService;
import org.dspace.content.service.DSpaceObjectService;
import org.dspace.content.service.InstallItemService;
import org.dspace.content.service.ItemService;
import org.dspace.content.service.WorkspaceItemService;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.discovery.IndexingService;
import org.dspace.eperson.factory.EPersonServiceFactory;