Skip to content

Commit

Permalink
Change handling for boxExpander for when user does not select any files
Browse files Browse the repository at this point in the history
  • Loading branch information
A-bel committed Dec 11, 2023
1 parent 85033af commit f97817a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,6 @@ public TransferJobRequest createRequest(RequestFromODS odsTransferRequest) {
}
}
s.setInfoList(expandedFiles);

//TODO: fix box case handling where if no files selected by user (to match other cases)
}

transferJobRequest.setSource(s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,35 @@ public void createClient(EndpointCredential credential) {
public List<EntityInfo> expandedFileSystem(List<EntityInfo> userSelectedResources, String basePath) {
List<EntityInfo> transferFiles = new ArrayList<>();
Stack<BoxFolder> travStack = new Stack<>();//this will only hold folders to traverse
if(userSelectedResources.isEmpty()) return new ArrayList<>(); //we need to signal the cancellation of this transferjob request.
for(EntityInfo selectedResource : userSelectedResources){
boolean isFile = false;
try{
BoxFile temp = new BoxFile(this.connection, selectedResource.getId());
transferFiles.add(boxFileToEntityInfo(temp));
isFile = true;
}catch (BoxAPIException ignored){
logger.info("Tried to open {} as a file but it did not work", selectedResource.toString());
isFile = false;
}
if(!isFile){
try{
BoxFolder temp = new BoxFolder(this.connection, selectedResource.getId());
travStack.push(temp);
}catch (BoxAPIException ignored){
logger.info("Tried to open {} as a folder but it did not work", selectedResource.toString());
if (userSelectedResources.isEmpty()) {
//id = 0 represents root folder in box
BoxFolder temp = new BoxFolder(this.connection, "0");
travStack.push(temp);
} else {
for (EntityInfo selectedResource : userSelectedResources) {
boolean isFile = false;
try {
BoxFile temp = new BoxFile(this.connection, selectedResource.getId());
transferFiles.add(boxFileToEntityInfo(temp));
isFile = true;
} catch (BoxAPIException ignored) {
logger.info("Tried to open {} as a file but it did not work", selectedResource.toString());
isFile = false;
}
if (!isFile) {
try {
BoxFolder temp = new BoxFolder(this.connection, selectedResource.getId());
travStack.push(temp);
} catch (BoxAPIException ignored) {
logger.info("Tried to open {} as a folder but it did not work", selectedResource.toString());
}
}
}
}
while(!travStack.isEmpty()){

while (!travStack.isEmpty()) {
BoxFolder folder = travStack.pop();
for(BoxItem.Info child : folder){
for (BoxItem.Info child : folder) {
if (child instanceof BoxFile.Info) {
BoxFile.Info fileInfo = (BoxFile.Info) child;
BoxFile boxFile = new BoxFile(this.connection, fileInfo.getID());
Expand All @@ -72,18 +78,18 @@ public List<EntityInfo> expandedDestFileSystem(String basePath) {
List<EntityInfo> destFilesList = new ArrayList<>();
Stack<BoxFolder> travStack = new Stack<>();//this will only hold folders to traverse

try{
try {
//id = 0 represents root folder in box
BoxFolder temp = new BoxFolder(this.connection, "0");
travStack.push(temp);
}catch (BoxAPIException ignored){
} catch (BoxAPIException ignored) {
logger.info("Tried to open {} as a folder but it did not work", "0");
}


while(!travStack.isEmpty()){
while (!travStack.isEmpty()) {
BoxFolder folder = travStack.pop();
for(BoxItem.Info child : folder){
for (BoxItem.Info child : folder) {
//ignore folders, if a file, add to list
if (child instanceof BoxFile.Info) {
BoxFile.Info fileInfo = (BoxFile.Info) child;
Expand All @@ -98,10 +104,10 @@ public List<EntityInfo> expandedDestFileSystem(String basePath) {
@Override
public List<EntityInfo> destinationChunkSize(List<EntityInfo> expandedFiles, String basePath, Integer userChunkSize) {
BoxFolder destinationUploadFolder = new BoxFolder(this.connection, basePath);
for(EntityInfo entityInfo : expandedFiles){
if(entityInfo.getSize() < 1024*1024*20){
for (EntityInfo entityInfo : expandedFiles) {
if (entityInfo.getSize() < 1024 * 1024 * 20) {
entityInfo.setChunkSize(Math.toIntExact(entityInfo.getSize()));
}else{
} else {
BoxFileUploadSession.Info uploadSession = destinationUploadFolder.createUploadSession(entityInfo.getId(), entityInfo.getSize());
entityInfo.setChunkSize(uploadSession.getPartSize());
}
Expand Down

0 comments on commit f97817a

Please sign in to comment.