mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 07:23:08 +00:00
[Task 71405] fixed the Process Files endpoints and added two tests for them
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
package org.dspace.scripts;
|
package org.dspace.scripts;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
@@ -176,6 +177,9 @@ public class Process implements ReloadableEntity<Integer> {
|
|||||||
* @return The Bitstreams that are used or created by the process
|
* @return The Bitstreams that are used or created by the process
|
||||||
*/
|
*/
|
||||||
public List<Bitstream> getBitstreams() {
|
public List<Bitstream> getBitstreams() {
|
||||||
|
if (bitstreams == null) {
|
||||||
|
bitstreams = new LinkedList<>();
|
||||||
|
}
|
||||||
return bitstreams;
|
return bitstreams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -206,10 +206,12 @@ public class ProcessServiceImpl implements ProcessService {
|
|||||||
if (type == null) {
|
if (type == null) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
for (Bitstream bitstream : allBitstreams) {
|
if (allBitstreams != null) {
|
||||||
if (StringUtils.equals(bitstreamService.getMetadata(bitstream, Process.BITSTREAM_TYPE_METADATAFIELD),
|
for (Bitstream bitstream : allBitstreams) {
|
||||||
type)) {
|
if (StringUtils.equals(bitstreamService.getMetadata(bitstream,
|
||||||
return bitstream;
|
Process.BITSTREAM_TYPE_METADATAFIELD), type)) {
|
||||||
|
return bitstream;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -73,7 +73,7 @@ public class ProcessFilesLinkRepository extends AbstractDSpaceRestRepository imp
|
|||||||
* @throws AuthorizeException If something goes wrong
|
* @throws AuthorizeException If something goes wrong
|
||||||
*/
|
*/
|
||||||
@PreAuthorize("hasPermission(#processId, 'PROCESS', 'READ')")
|
@PreAuthorize("hasPermission(#processId, 'PROCESS', 'READ')")
|
||||||
public BitstreamRest getFileFromProcessByType(HttpServletRequest request, String processId, String fileType,
|
public BitstreamRest getResource(HttpServletRequest request, String processId, String fileType,
|
||||||
Pageable pageable, Projection projection)
|
Pageable pageable, Projection projection)
|
||||||
throws SQLException, AuthorizeException {
|
throws SQLException, AuthorizeException {
|
||||||
if (log.isTraceEnabled()) {
|
if (log.isTraceEnabled()) {
|
||||||
|
@@ -13,16 +13,17 @@ 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.jsonPath;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.InputStream;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.codec.CharEncoding;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.dspace.app.rest.builder.ProcessBuilder;
|
import org.dspace.app.rest.builder.ProcessBuilder;
|
||||||
import org.dspace.app.rest.matcher.PageMatcher;
|
import org.dspace.app.rest.matcher.PageMatcher;
|
||||||
import org.dspace.app.rest.matcher.ProcessMatcher;
|
import org.dspace.app.rest.matcher.ProcessMatcher;
|
||||||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.content.Bitstream;
|
||||||
import org.dspace.content.ProcessStatus;
|
import org.dspace.content.ProcessStatus;
|
||||||
import org.dspace.scripts.DSpaceCommandLineParameter;
|
import org.dspace.scripts.DSpaceCommandLineParameter;
|
||||||
import org.dspace.scripts.Process;
|
import org.dspace.scripts.Process;
|
||||||
@@ -203,15 +204,48 @@ public class ProcessRestRepositoryIT extends AbstractControllerIntegrationTest {
|
|||||||
.andExpect(status().isForbidden());
|
.andExpect(status().isForbidden());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getProcessFiles() throws Exception {
|
||||||
|
Process newProcess = ProcessBuilder.createProcess(context, eperson, "mock-script", new LinkedList<>()).build();
|
||||||
|
|
||||||
|
try (InputStream is = IOUtils.toInputStream("Test File For Process", CharEncoding.UTF_8)) {
|
||||||
|
processService.appendFile(context, process, is, "inputfile", "test.csv");
|
||||||
|
}
|
||||||
|
Bitstream bitstream = processService.getBitstream(context, process, "inputfile");
|
||||||
|
|
||||||
|
String token = getAuthToken(admin.getEmail(), password);
|
||||||
|
|
||||||
|
getClient(token).perform(get("/api/system/processes/" + process.getID() + "/files"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$._embedded.inputfile[0].name", is("test.csv")))
|
||||||
|
.andExpect(jsonPath("$._embedded.inputfile[0].uuid", is(bitstream.getID().toString())))
|
||||||
|
.andExpect(jsonPath("$._embedded.inputfile[0].metadata['dspace.process.filetype']" +
|
||||||
|
"[0].value", is("inputfile")));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getProcessFilesByFileType() throws Exception {
|
||||||
|
Process newProcess = ProcessBuilder.createProcess(context, eperson, "mock-script", new LinkedList<>()).build();
|
||||||
|
|
||||||
|
try (InputStream is = IOUtils.toInputStream("Test File For Process", CharEncoding.UTF_8)) {
|
||||||
|
processService.appendFile(context, process, is, "inputfile", "test.csv");
|
||||||
|
}
|
||||||
|
Bitstream bitstream = processService.getBitstream(context, process, "inputfile");
|
||||||
|
|
||||||
|
String token = getAuthToken(admin.getEmail(), password);
|
||||||
|
|
||||||
|
getClient(token).perform(get("/api/system/processes/" + process.getID() + "/files/inputfile"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$._embedded.bitstreams[0].name", is("test.csv")))
|
||||||
|
.andExpect(jsonPath("$._embedded.bitstreams[0].uuid", is(bitstream.getID().toString())))
|
||||||
|
.andExpect(jsonPath("$._embedded.bitstreams[0].metadata['dspace.process.filetype']" +
|
||||||
|
"[0].value", is("inputfile")));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void destroy() throws Exception {
|
public void destroy() throws Exception {
|
||||||
CollectionUtils.emptyIfNull(processService.findAll(context)).stream().forEach(process -> {
|
|
||||||
try {
|
|
||||||
processService.delete(context, process);
|
|
||||||
} catch (SQLException | IOException | AuthorizeException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
super.destroy();
|
super.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -43,6 +43,7 @@ public class ProcessBuilder extends AbstractBuilder<Process, ProcessService> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void cleanup() throws Exception {
|
public void cleanup() throws Exception {
|
||||||
try (Context c = new Context()) {
|
try (Context c = new Context()) {
|
||||||
c.turnOffAuthorisationSystem();
|
c.turnOffAuthorisationSystem();
|
||||||
|
Reference in New Issue
Block a user