mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 10:04:21 +00:00
Fixed feedback
This commit is contained in:
@@ -20,7 +20,7 @@ import org.apache.logging.log4j.Logger;
|
|||||||
import org.dspace.app.rest.converter.BitstreamConverter;
|
import org.dspace.app.rest.converter.BitstreamConverter;
|
||||||
import org.dspace.app.rest.converter.MetadataConverter;
|
import org.dspace.app.rest.converter.MetadataConverter;
|
||||||
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||||
import org.dspace.app.rest.model.BitstreamPropertiesRest;
|
import org.dspace.app.rest.model.BitstreamRest;
|
||||||
import org.dspace.app.rest.model.hateoas.BitstreamResource;
|
import org.dspace.app.rest.model.hateoas.BitstreamResource;
|
||||||
import org.dspace.app.rest.utils.ContextUtil;
|
import org.dspace.app.rest.utils.ContextUtil;
|
||||||
import org.dspace.app.rest.utils.Utils;
|
import org.dspace.app.rest.utils.Utils;
|
||||||
@@ -66,6 +66,12 @@ public class ItemUploadController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private BitstreamFormatService bitstreamFormatService;
|
private BitstreamFormatService bitstreamFormatService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to upload a Bitstream to an Item with the given UUID in the URL. This will create a Bitstream with the
|
||||||
|
* file provided in the request and attach this to the Item that matches the UUID in the URL.
|
||||||
|
* This will only work for uploading one file, any extra files will silently be ignored
|
||||||
|
* @return The created BitstreamResource
|
||||||
|
*/
|
||||||
@RequestMapping(method = RequestMethod.POST, value = "/bitstreams", headers = "content-type=multipart/form-data")
|
@RequestMapping(method = RequestMethod.POST, value = "/bitstreams", headers = "content-type=multipart/form-data")
|
||||||
@PreAuthorize("hasPermission(#uuid, 'ITEM', 'WRITE') && hasPermission(#uuid, 'ITEM', 'ADD')")
|
@PreAuthorize("hasPermission(#uuid, 'ITEM', 'WRITE') && hasPermission(#uuid, 'ITEM', 'ADD')")
|
||||||
public BitstreamResource uploadBitstream(HttpServletRequest request, @PathVariable UUID uuid,
|
public BitstreamResource uploadBitstream(HttpServletRequest request, @PathVariable UUID uuid,
|
||||||
@@ -113,27 +119,27 @@ public class ItemUploadController {
|
|||||||
Bitstream bitstream = null;
|
Bitstream bitstream = null;
|
||||||
if (StringUtils.isNotBlank(properties)) {
|
if (StringUtils.isNotBlank(properties)) {
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
BitstreamPropertiesRest bitstreamPropertiesRest = null;
|
BitstreamRest bitstreamRest = null;
|
||||||
try {
|
try {
|
||||||
bitstreamPropertiesRest = mapper.readValue(properties, BitstreamPropertiesRest.class);
|
bitstreamRest = mapper.readValue(properties, BitstreamRest.class);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new UnprocessableEntityException("The properties parameter was incorrect: " + properties);
|
throw new UnprocessableEntityException("The properties parameter was incorrect: " + properties);
|
||||||
}
|
}
|
||||||
String bundleName = bitstreamPropertiesRest.getBundleName();
|
String bundleName = bitstreamRest.getBundleName();
|
||||||
if (StringUtils.isBlank(bundleName)) {
|
if (StringUtils.isBlank(bundleName)) {
|
||||||
throw new UnprocessableEntityException("Properties without a bundleName is not allowed");
|
throw new UnprocessableEntityException("Properties without a bundleName is not allowed");
|
||||||
}
|
}
|
||||||
bitstream = itemService.createSingleBitstream(context, fileInputStream, item, bundleName);
|
bitstream = itemService.createSingleBitstream(context, fileInputStream, item, bundleName);
|
||||||
if (bitstreamPropertiesRest.getMetadata() != null) {
|
if (bitstreamRest.getMetadata() != null) {
|
||||||
metadataConverter.setMetadata(context, bitstream, bitstreamPropertiesRest.getMetadata());
|
metadataConverter.setMetadata(context, bitstream, bitstreamRest.getMetadata());
|
||||||
}
|
}
|
||||||
String name = bitstreamPropertiesRest.getName();
|
String name = bitstreamRest.getName();
|
||||||
if (StringUtils.isNotBlank(name)) {
|
if (StringUtils.isNotBlank(name)) {
|
||||||
bitstream.setName(context, name);
|
bitstream.setName(context, name);
|
||||||
} else {
|
} else {
|
||||||
bitstream.setName(context, originalFilename);
|
bitstream.setName(context, originalFilename);
|
||||||
}
|
}
|
||||||
Integer sequenceId = bitstreamPropertiesRest.getSequenceId();
|
Integer sequenceId = bitstreamRest.getSequenceId();
|
||||||
if (sequenceId != null) {
|
if (sequenceId != null) {
|
||||||
try {
|
try {
|
||||||
bitstreamService.setSequenceId(context, bitstream, item, sequenceId);
|
bitstreamService.setSequenceId(context, bitstream, item, sequenceId);
|
||||||
|
@@ -1,48 +0,0 @@
|
|||||||
/**
|
|
||||||
* The contents of this file are subject to the license and copyright
|
|
||||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
|
||||||
* tree and available online at
|
|
||||||
*
|
|
||||||
* http://www.dspace.org/license/
|
|
||||||
*/
|
|
||||||
package org.dspace.app.rest.model;
|
|
||||||
|
|
||||||
public class BitstreamPropertiesRest {
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
private String bundleName;
|
|
||||||
private Integer sequenceId;
|
|
||||||
private MetadataRest metadata;
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBundleName() {
|
|
||||||
return bundleName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBundleName(String bundleName) {
|
|
||||||
this.bundleName = bundleName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MetadataRest getMetadata() {
|
|
||||||
return metadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMetadata(MetadataRest metadata) {
|
|
||||||
this.metadata = metadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getSequenceId() {
|
|
||||||
return sequenceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSequenceId(Integer sequenceId) {
|
|
||||||
this.sequenceId = sequenceId;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -76,6 +76,7 @@ public class BitstreamRest extends DSpaceObjectRest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
@@ -23,7 +23,7 @@ import org.dspace.app.rest.builder.CommunityBuilder;
|
|||||||
import org.dspace.app.rest.builder.ItemBuilder;
|
import org.dspace.app.rest.builder.ItemBuilder;
|
||||||
import org.dspace.app.rest.matcher.BitstreamMatcher;
|
import org.dspace.app.rest.matcher.BitstreamMatcher;
|
||||||
import org.dspace.app.rest.matcher.MetadataMatcher;
|
import org.dspace.app.rest.matcher.MetadataMatcher;
|
||||||
import org.dspace.app.rest.model.BitstreamPropertiesRest;
|
import org.dspace.app.rest.model.BitstreamRest;
|
||||||
import org.dspace.app.rest.model.MetadataRest;
|
import org.dspace.app.rest.model.MetadataRest;
|
||||||
import org.dspace.app.rest.model.MetadataValueRest;
|
import org.dspace.app.rest.model.MetadataValueRest;
|
||||||
import org.dspace.app.rest.test.AbstractEntityIntegrationTest;
|
import org.dspace.app.rest.test.AbstractEntityIntegrationTest;
|
||||||
@@ -73,10 +73,10 @@ public class ItemUploadControllerIT extends AbstractEntityIntegrationTest {
|
|||||||
MockMultipartFile file = new MockMultipartFile("file", "hello.txt", MediaType.TEXT_PLAIN_VALUE,
|
MockMultipartFile file = new MockMultipartFile("file", "hello.txt", MediaType.TEXT_PLAIN_VALUE,
|
||||||
input.getBytes());
|
input.getBytes());
|
||||||
|
|
||||||
BitstreamPropertiesRest bitstreamPropertiesRest = new BitstreamPropertiesRest();
|
BitstreamRest bitstreamRest = new BitstreamRest();
|
||||||
bitstreamPropertiesRest.setBundleName("TESTINGBUNDLE");
|
bitstreamRest.setBundleName("TESTINGBUNDLE");
|
||||||
bitstreamPropertiesRest.setName("testing");
|
bitstreamRest.setName("testing");
|
||||||
bitstreamPropertiesRest.setSequenceId(123456);
|
bitstreamRest.setSequenceId(123456);
|
||||||
|
|
||||||
MetadataRest metadataRest = new MetadataRest();
|
MetadataRest metadataRest = new MetadataRest();
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ public class ItemUploadControllerIT extends AbstractEntityIntegrationTest {
|
|||||||
title.setValue("Title Text");
|
title.setValue("Title Text");
|
||||||
metadataRest.put("dc.title", title);
|
metadataRest.put("dc.title", title);
|
||||||
|
|
||||||
bitstreamPropertiesRest.setMetadata(metadataRest);
|
bitstreamRest.setMetadata(metadataRest);
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
context.restoreAuthSystemState();
|
context.restoreAuthSystemState();
|
||||||
@@ -104,7 +104,7 @@ public class ItemUploadControllerIT extends AbstractEntityIntegrationTest {
|
|||||||
MockMvcRequestBuilders.fileUpload("/api/core/items/" + item.getID() + "/bitstreams")
|
MockMvcRequestBuilders.fileUpload("/api/core/items/" + item.getID() + "/bitstreams")
|
||||||
.file(file)
|
.file(file)
|
||||||
.param("properties", mapper
|
.param("properties", mapper
|
||||||
.writeValueAsString(bitstreamPropertiesRest)))
|
.writeValueAsString(bitstreamRest)))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(jsonPath("$.name", is("testing")))
|
.andExpect(jsonPath("$.name", is("testing")))
|
||||||
.andExpect(jsonPath("$.bundleName", is("TESTINGBUNDLE")))
|
.andExpect(jsonPath("$.bundleName", is("TESTINGBUNDLE")))
|
||||||
@@ -335,9 +335,9 @@ public class ItemUploadControllerIT extends AbstractEntityIntegrationTest {
|
|||||||
MockMultipartFile file = new MockMultipartFile("file", "hello.txt", MediaType.TEXT_PLAIN_VALUE,
|
MockMultipartFile file = new MockMultipartFile("file", "hello.txt", MediaType.TEXT_PLAIN_VALUE,
|
||||||
input.getBytes());
|
input.getBytes());
|
||||||
|
|
||||||
BitstreamPropertiesRest bitstreamPropertiesRest = new BitstreamPropertiesRest();
|
BitstreamRest bitstreamRest = new BitstreamRest();
|
||||||
String testbundle = "TESTBUNDLE";
|
String testbundle = "TESTBUNDLE";
|
||||||
bitstreamPropertiesRest.setBundleName(testbundle);
|
bitstreamRest.setBundleName(testbundle);
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
@@ -347,7 +347,7 @@ public class ItemUploadControllerIT extends AbstractEntityIntegrationTest {
|
|||||||
.perform(MockMvcRequestBuilders.fileUpload("/api/core/items/" + item.getID() + "/bitstreams")
|
.perform(MockMvcRequestBuilders.fileUpload("/api/core/items/" + item.getID() + "/bitstreams")
|
||||||
.file(file)
|
.file(file)
|
||||||
.param("properties", mapper
|
.param("properties", mapper
|
||||||
.writeValueAsString(bitstreamPropertiesRest)))
|
.writeValueAsString(bitstreamRest)))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(jsonPath("$.bundleName", is(testbundle)))
|
.andExpect(jsonPath("$.bundleName", is(testbundle)))
|
||||||
.andExpect(jsonPath("$.uuid", notNullValue())).andReturn();
|
.andExpect(jsonPath("$.uuid", notNullValue())).andReturn();
|
||||||
@@ -430,7 +430,7 @@ public class ItemUploadControllerIT extends AbstractEntityIntegrationTest {
|
|||||||
MockMultipartFile file = new MockMultipartFile("file", "hello.txt", MediaType.TEXT_PLAIN_VALUE,
|
MockMultipartFile file = new MockMultipartFile("file", "hello.txt", MediaType.TEXT_PLAIN_VALUE,
|
||||||
input.getBytes());
|
input.getBytes());
|
||||||
|
|
||||||
BitstreamPropertiesRest bitstreamPropertiesRest = new BitstreamPropertiesRest();
|
BitstreamRest bitstreamRest = new BitstreamRest();
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
@@ -439,7 +439,7 @@ public class ItemUploadControllerIT extends AbstractEntityIntegrationTest {
|
|||||||
getClient(token).perform(MockMvcRequestBuilders.fileUpload("/api/core/items/" + item.getID() + "/bitstreams")
|
getClient(token).perform(MockMvcRequestBuilders.fileUpload("/api/core/items/" + item.getID() + "/bitstreams")
|
||||||
.file(file)
|
.file(file)
|
||||||
.param("properties", mapper
|
.param("properties", mapper
|
||||||
.writeValueAsString(bitstreamPropertiesRest)))
|
.writeValueAsString(bitstreamRest)))
|
||||||
.andExpect(status().isUnprocessableEntity());
|
.andExpect(status().isUnprocessableEntity());
|
||||||
|
|
||||||
getClient(token).perform(get("/api/core/items/" + item.getID() + "/bitstreams"))
|
getClient(token).perform(get("/api/core/items/" + item.getID() + "/bitstreams"))
|
||||||
@@ -448,7 +448,6 @@ public class ItemUploadControllerIT extends AbstractEntityIntegrationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//TODO This check on sequence ID doesn't happen
|
|
||||||
@Test
|
@Test
|
||||||
public void uploadBitstreamSameSequenceIdTwiceUnprocessableEntityException() throws Exception {
|
public void uploadBitstreamSameSequenceIdTwiceUnprocessableEntityException() throws Exception {
|
||||||
context.turnOffAuthorisationSystem();
|
context.turnOffAuthorisationSystem();
|
||||||
@@ -476,10 +475,10 @@ public class ItemUploadControllerIT extends AbstractEntityIntegrationTest {
|
|||||||
MockMultipartFile file = new MockMultipartFile("file", "hello.txt", MediaType.TEXT_PLAIN_VALUE,
|
MockMultipartFile file = new MockMultipartFile("file", "hello.txt", MediaType.TEXT_PLAIN_VALUE,
|
||||||
input.getBytes());
|
input.getBytes());
|
||||||
|
|
||||||
BitstreamPropertiesRest bitstreamPropertiesRest = new BitstreamPropertiesRest();
|
BitstreamRest bitstreamRest = new BitstreamRest();
|
||||||
bitstreamPropertiesRest.setBundleName("ORIGINAL");
|
bitstreamRest.setBundleName("ORIGINAL");
|
||||||
bitstreamPropertiesRest.setName("testing");
|
bitstreamRest.setName("testing");
|
||||||
bitstreamPropertiesRest.setSequenceId(123456);
|
bitstreamRest.setSequenceId(123456);
|
||||||
|
|
||||||
MetadataRest metadataRest = new MetadataRest();
|
MetadataRest metadataRest = new MetadataRest();
|
||||||
|
|
||||||
@@ -499,14 +498,14 @@ public class ItemUploadControllerIT extends AbstractEntityIntegrationTest {
|
|||||||
title.setValue("Title Text");
|
title.setValue("Title Text");
|
||||||
metadataRest.put("dc.title", title);
|
metadataRest.put("dc.title", title);
|
||||||
|
|
||||||
bitstreamPropertiesRest.setMetadata(metadataRest);
|
bitstreamRest.setMetadata(metadataRest);
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
context.restoreAuthSystemState();
|
context.restoreAuthSystemState();
|
||||||
getClient(token).perform(MockMvcRequestBuilders.fileUpload("/api/core/items/" + item.getID() + "/bitstreams")
|
getClient(token).perform(MockMvcRequestBuilders.fileUpload("/api/core/items/" + item.getID() + "/bitstreams")
|
||||||
.file(file)
|
.file(file)
|
||||||
.param("properties", mapper
|
.param("properties", mapper
|
||||||
.writeValueAsString(bitstreamPropertiesRest)))
|
.writeValueAsString(bitstreamRest)))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(jsonPath("$.name", is("testing")))
|
.andExpect(jsonPath("$.name", is("testing")))
|
||||||
.andExpect(jsonPath("$.bundleName", is("ORIGINAL")))
|
.andExpect(jsonPath("$.bundleName", is("ORIGINAL")))
|
||||||
@@ -526,7 +525,7 @@ public class ItemUploadControllerIT extends AbstractEntityIntegrationTest {
|
|||||||
getClient(token).perform(MockMvcRequestBuilders.fileUpload("/api/core/items/" + item.getID() + "/bitstreams")
|
getClient(token).perform(MockMvcRequestBuilders.fileUpload("/api/core/items/" + item.getID() + "/bitstreams")
|
||||||
.file(file)
|
.file(file)
|
||||||
.param("properties", mapper
|
.param("properties", mapper
|
||||||
.writeValueAsString(bitstreamPropertiesRest)))
|
.writeValueAsString(bitstreamRest)))
|
||||||
.andExpect(status().isUnprocessableEntity());
|
.andExpect(status().isUnprocessableEntity());
|
||||||
|
|
||||||
getClient(token).perform(get("/api/core/items/" + item.getID() + "/bitstreams"))
|
getClient(token).perform(get("/api/core/items/" + item.getID() + "/bitstreams"))
|
||||||
|
Reference in New Issue
Block a user