Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bxc 4771 upper file limit #1835

Merged
merged 6 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class DownloadBulkService {
private AccessControlService aclService;
private RepositoryObjectLoader repoObjLoader;
private Path basePath;
private int fileLimit;

public Path downloadBulk(DownloadBulkRequest request) {
var pidString = request.getWorkPidString();
Expand Down Expand Up @@ -60,7 +61,12 @@ private void zipFiles(WorkObject workObject, AccessGroupSet agentPrincipals, Pat
}

Map<String, Integer> duplicates = new HashMap<>();
int count = 0;
var loopLimit = getLoopLimit(memberObjects.size());
for (ContentObject memberObject : memberObjects ) {
if (count == loopLimit) {
sharonluong marked this conversation as resolved.
Show resolved Hide resolved
break;
}
if (!(memberObject instanceof FileObject)) {
continue;
}
Expand All @@ -84,6 +90,7 @@ private void zipFiles(WorkObject workObject, AccessGroupSet agentPrincipals, Pat

IOUtils.copy(binaryStream, zipOut);
}
count++;
}
}
}
Expand All @@ -101,6 +108,9 @@ private String formatFilename(String filename, int copyNumber) {
var base = FilenameUtils.removeExtension(filename);
return base + "(" + copyNumber + ")." + extension;
}
private int getLoopLimit(int arraySize) {
return Math.min(fileLimit, arraySize);
}

public void setAclService(AccessControlService aclService) {
this.aclService = aclService;
Expand All @@ -113,4 +123,8 @@ public void setRepoObjLoader(RepositoryObjectLoader repoObjLoader) {
public void setBasePath(Path basePath) {
this.basePath = basePath;
}

public void setFileLimit(int fileLimit) {
this.fileLimit = fileLimit;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void init() throws Exception {
service.setAclService(aclService);
service.setRepoObjLoader(repoObjLoader);
service.setBasePath(zipStorageBasePath);
service.setFileLimit(5);
parentPid = PIDs.get(PARENT_UUID);
fileObject1Pid = PIDs.get(CHILD1_UUID);
fileObject2Pid = PIDs.get(CHILD2_UUID);
Expand Down Expand Up @@ -165,6 +166,22 @@ public void tombstoneTest() throws IOException {
assertZipFiles(List.of(), List.of());
}

@Test
public void fileLimitTest() throws IOException {
when(repoObjLoader.getWorkObject(any(PID.class))).thenReturn(parentWork);
when(parentWork.getMembers()).thenReturn(List.of(fileObject1, fileObject2));
makeBinaryObject(fileObject1, FILENAME1);
makeBinaryObject(fileObject2, FILENAME2);
when(aclService.hasAccess(eq(fileObject1Pid), any(),
eq(Permission.viewOriginal))).thenReturn(true);
when(aclService.hasAccess(eq(fileObject2Pid), any(),
eq(Permission.viewOriginal))).thenReturn(true);
service.setFileLimit(1);
service.downloadBulk(request);
// the zip file should have one entry
assertZipFiles(List.of(FILENAME1), List.of("flower"));
}

@Test
public void successTest() throws IOException {
when(repoObjLoader.getWorkObject(eq(parentPid))).thenReturn(parentWork);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@
<property name="aclService" ref="aclService"/>
<property name="repoObjLoader" ref="repositoryObjectLoader"/>
<property name="basePath" value="${data.dir}/zip/"/>
<property name="fileLimit" value="100" />
</bean>

<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void init() throws FileNotFoundException {
downloadBulkService.setAclService(aclService);
downloadBulkService.setBasePath(tmpFolder);
downloadBulkService.setRepoObjLoader(repositoryObjectLoader);
downloadBulkService.setFileLimit(5);
controller.setDownloadBulkService(downloadBulkService);
fileInputStream = new FileInputStream("src/test/resources/__files/bunny.jpg");
mvc = MockMvcBuilders.standaloneSetup(controller)
Expand Down
Loading