mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 10:04:21 +00:00
[Task 70750] made the Bitstream findAll endpoint not implemented
This commit is contained in:
@@ -10,17 +10,14 @@ package org.dspace.app.rest.repository;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
||||||
|
import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException;
|
||||||
import org.dspace.app.rest.model.BitstreamRest;
|
import org.dspace.app.rest.model.BitstreamRest;
|
||||||
import org.dspace.app.rest.model.BundleRest;
|
import org.dspace.app.rest.model.BundleRest;
|
||||||
import org.dspace.app.rest.model.patch.Patch;
|
import org.dspace.app.rest.model.patch.Patch;
|
||||||
import org.dspace.app.rest.projection.Projection;
|
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.authorize.service.AuthorizeService;
|
import org.dspace.authorize.service.AuthorizeService;
|
||||||
import org.dspace.content.Bitstream;
|
import org.dspace.content.Bitstream;
|
||||||
@@ -34,7 +31,6 @@ import org.dspace.content.service.CommunityService;
|
|||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageImpl;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
@@ -95,22 +91,7 @@ public class BitstreamRestRepository extends DSpaceObjectRestRepository<Bitstrea
|
|||||||
@Override
|
@Override
|
||||||
@PreAuthorize("hasAuthority('ADMIN')")
|
@PreAuthorize("hasAuthority('ADMIN')")
|
||||||
public Page<BitstreamRest> findAll(Context context, Pageable pageable) {
|
public Page<BitstreamRest> findAll(Context context, Pageable pageable) {
|
||||||
List<Bitstream> bit = new ArrayList<Bitstream>();
|
throw new RepositoryMethodNotImplementedException(BitstreamRest.NAME, "findAll");
|
||||||
Iterator<Bitstream> it = null;
|
|
||||||
int total = 0;
|
|
||||||
try {
|
|
||||||
total = bs.countTotal(context);
|
|
||||||
it = bs.findAll(context, pageable.getPageSize(), Math.toIntExact(pageable.getOffset()));
|
|
||||||
while (it.hasNext()) {
|
|
||||||
bit.add(it.next());
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
Projection projection = utils.obtainProjection();
|
|
||||||
Page<BitstreamRest> page = new PageImpl<>(bit, pageable, total)
|
|
||||||
.map((bitstream) -> converter.toRest(bitstream, projection));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -39,7 +39,6 @@ import org.dspace.content.Community;
|
|||||||
import org.dspace.content.Item;
|
import org.dspace.content.Item;
|
||||||
import org.dspace.content.service.BitstreamService;
|
import org.dspace.content.service.BitstreamService;
|
||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
import org.hamcrest.Matchers;
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -97,14 +96,8 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest
|
|||||||
|
|
||||||
String token = getAuthToken(admin.getEmail(), password);
|
String token = getAuthToken(admin.getEmail(), password);
|
||||||
|
|
||||||
getClient(token).perform(get("/api/core/bitstreams/")
|
getClient(token).perform(get("/api/core/bitstreams/"))
|
||||||
.param("projection", "full"))
|
.andExpect(status().isMethodNotAllowed());
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andExpect(content().contentType(contentType))
|
|
||||||
.andExpect(jsonPath("$._embedded.bitstreams", Matchers.containsInAnyOrder(
|
|
||||||
BitstreamMatcher.matchBitstreamEntry(bitstream),
|
|
||||||
BitstreamMatcher.matchBitstreamEntry(bitstream1)
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -158,33 +151,13 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest
|
|||||||
getClient(token).perform(get("/api/core/bitstreams/")
|
getClient(token).perform(get("/api/core/bitstreams/")
|
||||||
.param("size", "1")
|
.param("size", "1")
|
||||||
.param("projection", "full"))
|
.param("projection", "full"))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isMethodNotAllowed());
|
||||||
.andExpect(content().contentType(contentType))
|
|
||||||
.andExpect(jsonPath("$._embedded.bitstreams", Matchers.contains(
|
|
||||||
BitstreamMatcher.matchBitstreamEntry(bitstream))
|
|
||||||
))
|
|
||||||
.andExpect(jsonPath("$._embedded.bitstreams", Matchers.not(
|
|
||||||
Matchers.contains(
|
|
||||||
BitstreamMatcher.matchBitstreamEntry(bitstream1))
|
|
||||||
)
|
|
||||||
))
|
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
getClient(token).perform(get("/api/core/bitstreams/")
|
getClient(token).perform(get("/api/core/bitstreams/")
|
||||||
.param("size", "1")
|
.param("size", "1")
|
||||||
.param("page", "1")
|
.param("page", "1")
|
||||||
.param("projection", "full"))
|
.param("projection", "full"))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isMethodNotAllowed());
|
||||||
.andExpect(content().contentType(contentType))
|
|
||||||
.andExpect(jsonPath("$._embedded.bitstreams", Matchers.contains(
|
|
||||||
BitstreamMatcher.matchBitstreamEntry(bitstream1)
|
|
||||||
)))
|
|
||||||
.andExpect(jsonPath("$._embedded.bitstreams", Matchers.not(
|
|
||||||
Matchers.contains(
|
|
||||||
BitstreamMatcher.matchBitstreamEntry(bitstream)
|
|
||||||
)
|
|
||||||
)));
|
|
||||||
|
|
||||||
getClient().perform(get("/api/core/bitstreams/"))
|
getClient().perform(get("/api/core/bitstreams/"))
|
||||||
.andExpect(status().isUnauthorized());
|
.andExpect(status().isUnauthorized());
|
||||||
|
@@ -38,7 +38,6 @@ public class EmptyRestRepositoryIT extends AbstractControllerIntegrationTest {
|
|||||||
|
|
||||||
//Test retrieval of all bitstreams while none exist
|
//Test retrieval of all bitstreams while none exist
|
||||||
getClient(token).perform(get("/api/core/bitstreams"))
|
getClient(token).perform(get("/api/core/bitstreams"))
|
||||||
. andExpect(status().isOk())
|
. andExpect(status().isMethodNotAllowed());
|
||||||
.andExpect(jsonPath("$.page.totalElements", is(0)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user