Skip to content

Commit 2faa788

Browse files
committed
Fix: continuation-token support in GetBucket API
Signed-off-by: RichardLea <chigix@zoho.com>
1 parent f784a28 commit 2faa788

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

src/main/java/com/chigix/resserver/domain/model/resource/ResourceRepository.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ public interface ResourceRepository {
3030
*/
3131
Iterator<Resource> fetchResources(Specification<Resource> specification, int limit);
3232

33+
/**
34+
* Marks a resource in a fetched list relative to the iterator given as a
35+
* continuation point and returns the continuation token for next fetching
36+
* which could start from this target resource.
37+
*
38+
* @param fetched
39+
* @param continuePos
40+
* @return
41+
*/
42+
String markContinuationInFetchList(Iterator<Resource> fetched, Resource continuePos);
43+
3344
void removeResource(Resource resource) throws NoSuchKey, NoSuchBucket;
3445

3546
/**

src/main/java/com/chigix/resserver/endpoint/GetBucket/ResourceListHandler.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public int read() throws IOException {
125125
.and(resourceSpecifications.keyStartWith(listCtx.prefix));
126126
if (listCtx.continuationToken != null) {
127127
resourceSpecs.and(resourceSpecifications
128-
.continuateFrom(listCtx.nextContinuationToken));
128+
.continuateFrom(listCtx.continuationToken));
129129
}
130130
final Iterator<Resource> resources;
131131
resources = application.getEntityManager()
@@ -135,10 +135,13 @@ public int read() throws IOException {
135135
listCtx.maxKeys + 1);
136136
setStream(new IteratorInputStream<Resource>(resources) {
137137
@Override
138-
protected InputStream inputStreamProvider(Resource item) throws NoSuchElementException {
138+
protected InputStream inputStreamProvider(Resource item)
139+
throws NoSuchElementException {
139140
if (listCtx.keyCountTotal >= listCtx.maxKeys) {
140141
listCtx.isTruncated = true;
141-
listCtx.nextContinuationToken = item.getVersionId();
142+
listCtx.nextContinuationToken = application
143+
.getEntityManager().getResourceRepository()
144+
.markContinuationInFetchList(resources, item);
142145
return new ClosedInputStream();
143146
}
144147
byte_charging.setStream(new ByteArrayOutputStream());

src/main/java/com/chigix/resserver/mybatis/ResourceRepositoryImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,4 +289,12 @@ public void putChunk(ChunkedResource r, Chunk c, int chunkIndex) {
289289
chunkMapper.insert(record);
290290
}
291291

292+
@Override
293+
public String markContinuationInFetchList(Iterator<Resource> fetched, Resource continuePos) {
294+
if (continuePos instanceof ResourceExtension) {
295+
return ((ResourceExtension) continuePos).getKeyHash();
296+
}
297+
throw new RuntimeException("Unexpected!! Unpersisted Subresource Domain Object was passed.");
298+
}
299+
292300
}

0 commit comments

Comments
 (0)