Add link to the vocabularyEntryDetails search methods from the root

This commit is contained in:
Andrea Bollini
2020-07-18 16:07:04 +02:00
parent 07ffb5fbad
commit 9863b1c6d5
2 changed files with 29 additions and 1 deletions

View File

@@ -8,9 +8,11 @@
package org.dspace.app.rest.repository;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.dspace.app.rest.DiscoverableEndpointsService;
import org.dspace.app.rest.Parameter;
import org.dspace.app.rest.SearchRestMethod;
import org.dspace.app.rest.exception.LinkNotFoundException;
@@ -24,10 +26,12 @@ import org.dspace.content.authority.ChoiceAuthority;
import org.dspace.content.authority.Choices;
import org.dspace.content.authority.service.ChoiceAuthorityService;
import org.dspace.core.Context;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.hateoas.Link;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
@@ -37,7 +41,8 @@ import org.springframework.stereotype.Component;
* @author Andrea Bollini (andrea.bollini at 4science.it)
*/
@Component(VocabularyRest.CATEGORY + "." + VocabularyEntryDetailsRest.NAME)
public class VocabularyEntryDetailsRestRepository extends DSpaceRestRepository<VocabularyEntryDetailsRest, String> {
public class VocabularyEntryDetailsRestRepository extends DSpaceRestRepository<VocabularyEntryDetailsRest, String>
implements InitializingBean {
@Autowired
private ChoiceAuthorityService cas;
@@ -45,6 +50,16 @@ public class VocabularyEntryDetailsRestRepository extends DSpaceRestRepository<V
@Autowired
private AuthorityUtils authorityUtils;
@Autowired
private DiscoverableEndpointsService discoverableEndpointsService;
@Override
public void afterPropertiesSet() throws Exception {
discoverableEndpointsService.register(this, Arrays.asList(
new Link("/api/" + VocabularyRest.CATEGORY + "/" + VocabularyEntryDetailsRest.NAME + "/search",
VocabularyEntryDetailsRest.NAME + "-search")));
}
@PreAuthorize("hasAuthority('AUTHENTICATED')")
@Override
public Page<VocabularyEntryDetailsRest> findAll(Context context, Pageable pageable) {

View File

@@ -7,6 +7,7 @@
*/
package org.dspace.app.rest;
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.is;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
@@ -27,6 +28,18 @@ import org.junit.Test;
* @author Mykhaylo Boychuk (4science.it)
*/
public class VocabularyEntryDetailsIT extends AbstractControllerIntegrationTest {
@Test
public void discoverableNestedLinkTest() throws Exception {
String token = getAuthToken(eperson.getEmail(), password);
getClient(token).perform(get("/api"))
.andExpect(status().isOk())
.andExpect(jsonPath("$._links",Matchers.allOf(
hasJsonPath("$.vocabularyEntryDetails.href",
is("http://localhost/api/submission/vocabularyEntryDetails")),
hasJsonPath("$.vocabularyEntryDetails-search.href",
is("http://localhost/api/submission/vocabularyEntryDetails/search"))
)));
}
@Test
public void findAllTest() throws Exception {