Skip to content

Commit

Permalink
Fixes after rebase part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdesair committed Feb 8, 2018
1 parent 93a115a commit 0e0ec5a
Show file tree
Hide file tree
Showing 16 changed files with 155 additions and 164 deletions.
2 changes: 1 addition & 1 deletion dspace-spring-rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<version>1.2.2.RELEASE</version>
<version>1.2.3.RELEASE</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ public void retrieve(@PathVariable UUID uuid, HttpServletResponse response,
if (name == null) {
// give a default name to the file based on the UUID and the primary extension of the format
name = bit.getID().toString();
if (format != null && format.getExtensions() != null && format.getExtensions().size() > 0) {
if (format.getExtensions() != null && format.getExtensions().size() > 0) {
name += "." + format.getExtensions().get(0);
}
}

MultipartFileSender sender = MultipartFileSender
.fromInputStream(is)
.withBufferSize(BUFFER_SIZE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ private <ID extends Serializable> ResourceSupport findRelInternal(HttpServletReq
linkService.addLinks(resource);

String namespacedRel = utils.getNamespacedRel(modelObject, rel);
if (resource.getLink(rel) == null) {
if (resource.getLink(namespacedRel) == null) {
// TODO create a custom exception
throw new ResourceNotFoundException(rel + " undefined for " + model);
} else if (resource.getEmbeddedResources().get(namespacedRel) instanceof EmbeddedPage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package org.dspace.app.rest.model.hateoas;

import org.dspace.app.rest.model.BrowseEntryRest;
import org.dspace.app.rest.model.BrowseIndexRest;
import org.dspace.app.rest.model.hateoas.annotations.RelNameDSpaceResource;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
import java.util.TreeMap;

import org.apache.commons.lang.StringUtils;
import org.dspace.app.rest.model.RestModel;
import org.dspace.app.rest.model.RestAddressableModel;
import org.dspace.app.rest.security.StatelessAuthenticationFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.hateoas.IanaRels;
import org.springframework.hateoas.Link;
Expand All @@ -30,6 +33,8 @@
@Component
public class DSpaceCurieProvider extends DefaultCurieProvider {

private static final Logger log = LoggerFactory.getLogger(DSpaceCurieProvider.class);

private static final String SEPERATOR = ":";

private static final String SELF = "self";
Expand All @@ -49,7 +54,6 @@ public String getNamespacedRelFrom(Link link) {
}

public String getNamespacedRelFor(String rel) {
//TODO CLeanup
String category = extractPrefix(rel);
String coreRel = extractRel(rel);

Expand All @@ -66,7 +70,6 @@ private String extractRel(String rel) {
}

private String extractPrefix(String rel) {
//TODO Cleanup
if(StringUtils.containsNone(rel, SEPERATOR)){
return DEFAULT_CURIE;
}
Expand Down Expand Up @@ -94,13 +97,18 @@ public String getNamespacedRelFor(String category, String rel) {
return buildRel(category, rel);
}

public String getNamespacedRelFor(RestModel data, String rel) {
public String getNamespacedRelFor(RestAddressableModel data, String rel) {
return getNamespacedRelFor(data.getCategory(), rel);
}

public String getCurieForCategory(final String category) {
//TODO create mapping
return curiemapping.get(category);
String curie = curiemapping.get(category);
if(StringUtils.isBlank(curie)) {
log.warn("We don't have a curie mapping for category " + category);
return category;
} else {
return curie;
}
}

private String buildRel(String prefix, String rel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.dspace.app.rest.model.hateoas.DSpaceCurieProvider;
import org.dspace.app.rest.exception.PaginationException;
import org.dspace.app.rest.exception.RepositoryNotFoundException;
import org.dspace.app.rest.model.AuthorityRest;
import org.dspace.app.rest.model.CommunityRest;
import org.dspace.app.rest.model.RestAddressableModel;
import org.dspace.app.rest.model.LinkRest;
import org.dspace.app.rest.model.LinksRest;
import org.dspace.app.rest.model.ResourcePolicyRest;
import org.dspace.app.rest.model.RestModel;
import org.dspace.app.rest.model.RestAddressableModel;
import org.dspace.app.rest.model.hateoas.DSpaceCurieProvider;
import org.dspace.app.rest.model.hateoas.DSpaceResource;
import org.dspace.app.rest.repository.DSpaceRestRepository;
import org.dspace.app.rest.repository.LinkRestRepository;
Expand Down Expand Up @@ -174,7 +173,7 @@ public String getMetadataKey(String schema, String element, String qualifier) {
* @param <T>
* @return
*/
public <T extends RestModel> String getNamespacedRel(T data, String name) {
public <T extends RestAddressableModel> String getNamespacedRel(T data, String name) {
return curieProvider.getNamespacedRelFor(data, name);
}

Expand Down
4 changes: 2 additions & 2 deletions dspace-spring-rest/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ spring.http.encoding.charset=UTF-8
# Enable http encoding support.
spring.http.encoding.enabled=true
# Force the encoding to the configured charset on HTTP requests and responses.
spring.http.encoding.force=true
spring.http.encoding.force=false

###########################
# Embedded Tomcat Settings
Expand Down Expand Up @@ -114,4 +114,4 @@ spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSou
#logging.level.org.springframework.web=DEBUG
#logging.level.org.hibernate=ERROR

curiemapping={eperson:'p',core:'c',discover:'d'}
curiemapping={root:'r',core:'c',eperson:'p',discover:'d',config:'cf',integration:'i',submission:'s',authz:'az',authn:'an'}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@
import org.apache.commons.io.Charsets;
import org.apache.commons.lang.StringUtils;
import org.dspace.app.rest.Application;
import org.dspace.app.rest.model.hateoas.DSpaceCurieProvider;
import org.dspace.app.rest.security.WebSecurityConfiguration;
import org.dspace.app.rest.utils.ApplicationConfig;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -34,11 +32,11 @@
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.restdocs.JUnitRestDocumentation;
import org.springframework.restdocs.cli.CliDocumentation;
import org.springframework.restdocs.http.HttpDocumentation;
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentationConfigurer;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
Expand Down Expand Up @@ -84,9 +82,6 @@ public abstract class AbstractControllerIntegrationTest extends AbstractIntegrat
@Autowired
private List<Filter> requestFilters;

@Autowired
private DSpaceCurieProvider curieProvider;

@Autowired
void setConverters(HttpMessageConverter<?>[] converters) {

Expand All @@ -97,18 +92,6 @@ void setConverters(HttpMessageConverter<?>[] converters) {
this.mappingJackson2HttpMessageConverter);
}

@Rule
public JUnitRestDocumentation getRestDocumentation() {
if(restDocumentation == null) {
String curie = curieProvider.getCurieForCategory(getRestCategory());
restDocumentation = new JUnitRestDocumentation(DOCUMENTATION_SNIPPETS_DIR + curie);
}

return restDocumentation;
}

protected abstract String getRestCategory();

public MockMvc getClient() throws SQLException {
return getClient(null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.dspace.app.rest.test;

import org.dspace.app.rest.model.hateoas.DSpaceCurieProvider;
import org.junit.Rule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.restdocs.JUnitRestDocumentation;

/**
* Abstract class to write documentation tests
*/
public abstract class AbstractDocumentationTest extends AbstractControllerIntegrationTest {

@Autowired
private DSpaceCurieProvider curieProvider;

protected abstract String getRestCategory();

@Rule
public JUnitRestDocumentation getRestDocumentation() {
if(restDocumentation == null) {
String curie = curieProvider.getCurieForCategory(getRestCategory());
restDocumentation = new JUnitRestDocumentation(DOCUMENTATION_SNIPPETS_DIR + curie);
}

return restDocumentation;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

import org.dspace.app.rest.RootRestResourceController;
import org.dspace.app.rest.model.RestModel;
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
import org.dspace.app.rest.test.AbstractDocumentationTest;
import org.junit.Test;


/**
* Documentation test for the {@link RootRestResourceController}
*/
public class RootControllerDocumentation extends AbstractControllerIntegrationTest {
public class RootControllerDocumentation extends AbstractDocumentationTest {

protected String getRestCategory() {
return RestModel.CORE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,35 @@
*/
package org.dspace.documentation.bitstream;

import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.linkWithRel;
import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.relaxedLinks;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.relaxedResponseFields;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.io.InputStream;

import org.apache.commons.codec.CharEncoding;
import org.apache.commons.io.IOUtils;
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.ItemBuilder;
import org.dspace.app.rest.model.RestModel;
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
import org.dspace.app.rest.test.AbstractDocumentationTest;
import org.dspace.content.Bitstream;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.Item;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.eperson.EPerson;
import org.dspace.eperson.factory.EPersonServiceFactory;
import org.dspace.eperson.service.EPersonService;
import org.junit.Test;

import java.io.InputStream;

import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.linkWithRel;
import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.relaxedLinks;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.relaxedResponseFields;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;


/**
* Documentation test for the {@link org.dspace.app.rest.repository.BitstreamRestRepository}
*/
public class BitstreamControllerDocumentation extends AbstractControllerIntegrationTest {
public class BitstreamControllerDocumentation extends AbstractDocumentationTest {

protected String getRestCategory() {
return RestModel.CORE;
Expand All @@ -52,17 +48,17 @@ public void findOneBitstreamDocumentation() throws Exception {

//** GIVEN **
//1. A community-collection structure with one parent community with sub-community and two collections.
parentCommunity = new CommunityBuilder().createCommunity(context)
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity)
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = new CollectionBuilder().createCollection(context, child1).withName("Collection 1").build();
Collection col2 = new CollectionBuilder().createCollection(context, child1).withName("Collection 2").build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();

//2. Three public items that are readable by Anonymous with different subjects
Item publicItem1 = new ItemBuilder().createItem(context, col1)
Item publicItem1 = ItemBuilder.createItem(context, col1)
.withTitle("Public item 1")
.withIssueDate("2017-10-17")
.withAuthor("Smith, Donald").withAuthor("Doe, John")
Expand All @@ -73,7 +69,7 @@ public void findOneBitstreamDocumentation() throws Exception {
//Add a bitstream to an item
Bitstream bitstream = null;
try(InputStream is = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) {
bitstream = new BitstreamBuilder().
bitstream = BitstreamBuilder.
createBitstream(context, publicItem1, is)
.withName("Bitstream")
.build();
Expand Down Expand Up @@ -112,17 +108,17 @@ public void findAllBitstreamsDocumentation() throws Exception {

//** GIVEN **
//1. A community-collection structure with one parent community with sub-community and two collections.
parentCommunity = new CommunityBuilder().createCommunity(context)
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = new CommunityBuilder().createSubCommunity(context, parentCommunity)
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = new CollectionBuilder().createCollection(context, child1).withName("Collection 1").build();
Collection col2 = new CollectionBuilder().createCollection(context, child1).withName("Collection 2").build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();

//2. Three public items that are readable by Anonymous with different subjects
Item publicItem1 = new ItemBuilder().createItem(context, col1)
Item publicItem1 = ItemBuilder.createItem(context, col1)
.withTitle("Public item 1")
.withIssueDate("2017-10-17")
.withAuthor("Smith, Donald").withAuthor("Doe, John")
Expand All @@ -133,22 +129,22 @@ public void findAllBitstreamsDocumentation() throws Exception {
//Add a bitstream to an item
Bitstream bitstream = null;
try(InputStream is = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) {
bitstream = new BitstreamBuilder().
bitstream = BitstreamBuilder.
createBitstream(context, publicItem1, is)
.withName("Bitstream")
.build();
}

Bitstream bitstream1 = null;
try(InputStream is = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) {
bitstream = new BitstreamBuilder().
bitstream = BitstreamBuilder.
createBitstream(context, publicItem1, is)
.withName("Bitstream")
.build();
}
Bitstream bitstream2 = null;
try(InputStream is = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) {
bitstream = new BitstreamBuilder().
bitstream = BitstreamBuilder.
createBitstream(context, publicItem1, is)
.withName("Bitstream")
.build();
Expand Down
Loading

0 comments on commit 0e0ec5a

Please sign in to comment.