[Task 70750] made the Bitstream findAll endpoint not implemented

This commit is contained in:
Raf Ponsaerts
2020-05-06 16:38:27 +02:00
parent 5e212192af
commit 026c2308ec
3 changed files with 7 additions and 54 deletions

View File

@@ -10,17 +10,14 @@ package org.dspace.app.rest.repository;
import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
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.BundleRest;
import org.dspace.app.rest.model.patch.Patch;
import org.dspace.app.rest.projection.Projection;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.content.Bitstream;
@@ -34,7 +31,6 @@ import org.dspace.content.service.CommunityService;
import org.dspace.core.Context;
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.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.security.access.prepost.PreAuthorize;
@@ -95,22 +91,7 @@ public class BitstreamRestRepository extends DSpaceObjectRestRepository<Bitstrea
@Override
@PreAuthorize("hasAuthority('ADMIN')")
public Page<BitstreamRest> findAll(Context context, Pageable pageable) {
List<Bitstream> bit = new ArrayList<Bitstream>();
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;
throw new RepositoryMethodNotImplementedException(BitstreamRest.NAME, "findAll");
}
@Override

View File

@@ -39,7 +39,6 @@ import org.dspace.content.Community;
import org.dspace.content.Item;
import org.dspace.content.service.BitstreamService;
import org.dspace.eperson.EPerson;
import org.hamcrest.Matchers;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -97,14 +96,8 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest
String token = getAuthToken(admin.getEmail(), password);
getClient(token).perform(get("/api/core/bitstreams/")
.param("projection", "full"))
.andExpect(status().isOk())
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$._embedded.bitstreams", Matchers.containsInAnyOrder(
BitstreamMatcher.matchBitstreamEntry(bitstream),
BitstreamMatcher.matchBitstreamEntry(bitstream1)
)));
getClient(token).perform(get("/api/core/bitstreams/"))
.andExpect(status().isMethodNotAllowed());
}
@Test
@@ -158,33 +151,13 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest
getClient(token).perform(get("/api/core/bitstreams/")
.param("size", "1")
.param("projection", "full"))
.andExpect(status().isOk())
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$._embedded.bitstreams", Matchers.contains(
BitstreamMatcher.matchBitstreamEntry(bitstream))
))
.andExpect(jsonPath("$._embedded.bitstreams", Matchers.not(
Matchers.contains(
BitstreamMatcher.matchBitstreamEntry(bitstream1))
)
))
;
.andExpect(status().isMethodNotAllowed());
getClient(token).perform(get("/api/core/bitstreams/")
.param("size", "1")
.param("page", "1")
.param("projection", "full"))
.andExpect(status().isOk())
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$._embedded.bitstreams", Matchers.contains(
BitstreamMatcher.matchBitstreamEntry(bitstream1)
)))
.andExpect(jsonPath("$._embedded.bitstreams", Matchers.not(
Matchers.contains(
BitstreamMatcher.matchBitstreamEntry(bitstream)
)
)));
.andExpect(status().isMethodNotAllowed());
getClient().perform(get("/api/core/bitstreams/"))
.andExpect(status().isUnauthorized());

View File

@@ -38,7 +38,6 @@ public class EmptyRestRepositoryIT extends AbstractControllerIntegrationTest {
//Test retrieval of all bitstreams while none exist
getClient(token).perform(get("/api/core/bitstreams"))
. andExpect(status().isOk())
.andExpect(jsonPath("$.page.totalElements", is(0)));
. andExpect(status().isMethodNotAllowed());
}
}