Skip to content

Commit 83aa967

Browse files
committed
overwrite flag initial changes for HTTP, Box, DropBox and Gdrive
1 parent 8edc04f commit 83aa967

File tree

5 files changed

+75
-6
lines changed

5 files changed

+75
-6
lines changed

Diff for: src/main/java/com/onedatashare/scheduler/services/RequestModifier.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,18 @@ public List<EntityInfo> selectAndExpandDestination(TransferJobRequest.Destinatio
8484
return sftpExpander.expandedDestFileSystem(destination.getFileDestinationPath());
8585
case http:
8686
httpExpander.createClient(destination.getVfsDestCredential());
87-
return httpExpander.expandedFileSystem(selectedResources, destination.getFileDestinationPath());
87+
return httpExpander.expandedDestFileSystem(destination.getFileDestinationPath());
8888
case box:
8989
boxExpander.createClient(destination.getOauthDestCredential());
90-
return boxExpander.expandedFileSystem(selectedResources, destination.getFileDestinationPath());
90+
return boxExpander.expandedDestFileSystem(destination.getFileDestinationPath());
9191
case dropbox:
9292
dropBoxExpander.createClient(destination.getOauthDestCredential());
93-
return dropBoxExpander.expandedFileSystem(selectedResources, destination.getFileDestinationPath());
93+
return dropBoxExpander.expandedDestFileSystem(destination.getFileDestinationPath());
9494
case vfs:
9595
return selectedResources;
9696
case gdrive:
9797
gDriveExpander.createClient(destination.getOauthDestCredential());
98-
return gDriveExpander.expandedFileSystem(selectedResources, destination.getFileDestinationPath());
98+
return gDriveExpander.expandedDestFileSystem(destination.getFileDestinationPath());
9999

100100
}
101101
return null;
@@ -174,14 +174,14 @@ public TransferJobRequest createRequest(RequestFromODS odsTransferRequest) {
174174
if (transferJobRequest.getOptions().isOverwrite())
175175
s.setInfoList(expandedFiles);
176176
else {
177-
//Check files present in destination (given path level only) and remove them from infoList sent from source
177+
//Check files present in destination (given path level only)
178178

179179
//can use selectAndExpand but not for vfs
180180
List<EntityInfo> destExpandedFiles = this.selectAndExpandDestination(d, new ArrayList<>());
181181

182182

183183
/*
184-
for each file ID at dest, check if present in source list, if no, no action, if yes, remove that file id from src info list
184+
for each file ID at dest, check if present in source list, if yes, remove that file id from src info list
185185
expandedFiles.remove()
186186
s.setInfoList(expandedFiles);
187187
*/

Diff for: src/main/java/com/onedatashare/scheduler/services/expanders/BoxExpander.java

+28
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,34 @@ public List<EntityInfo> expandedFileSystem(List<EntityInfo> userSelectedResource
6767
return transferFiles;
6868
}
6969

70+
71+
public List<EntityInfo> expandedDestFileSystem(String basePath) {
72+
List<EntityInfo> destFilesList = new ArrayList<>();
73+
Stack<BoxFolder> travStack = new Stack<>();//this will only hold folders to traverse
74+
75+
try{
76+
//id = 0 represents root folder in box
77+
BoxFolder temp = new BoxFolder(this.connection, "0");
78+
travStack.push(temp);
79+
}catch (BoxAPIException ignored){
80+
logger.info("Tried to open {} as a folder but it did not work", "0");
81+
}
82+
83+
84+
while(!travStack.isEmpty()){
85+
BoxFolder folder = travStack.pop();
86+
for(BoxItem.Info child : folder){
87+
//ignore folders, if a file, add to list
88+
if (child instanceof BoxFile.Info) {
89+
BoxFile.Info fileInfo = (BoxFile.Info) child;
90+
BoxFile boxFile = new BoxFile(this.connection, fileInfo.getID());
91+
destFilesList.add(boxFileToEntityInfo(boxFile));
92+
}
93+
}
94+
}
95+
return destFilesList;
96+
}
97+
7098
@Override
7199
public List<EntityInfo> destinationChunkSize(List<EntityInfo> expandedFiles, String basePath, Integer userChunkSize) {
72100
BoxFolder destinationUploadFolder = new BoxFolder(this.connection, basePath);

Diff for: src/main/java/com/onedatashare/scheduler/services/expanders/DropBoxExpander.java

+15
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ public List<EntityInfo> expandedFileSystem(List<EntityInfo> userSelectedResource
7171
return expandedFiles;
7272
}
7373

74+
public List<EntityInfo> expandedDestFileSystem(String parentPath) {
75+
Stack<Metadata> traversalQueue = new Stack<>();
76+
List<EntityInfo> destFilesList = new ArrayList<>();
77+
if (parentPath == null || parentPath.isEmpty()) parentPath = "";
78+
//Expand all the files.
79+
80+
List<Metadata> resources = listOp(parentPath);
81+
for (Metadata resource : resources) {
82+
if (resource instanceof FileMetadata) {
83+
destFilesList.add(metaDataToFileInfo((FileMetadata) resource));
84+
}
85+
}
86+
return destFilesList;
87+
}
88+
7489
public EntityInfo metaDataToFileInfo(FileMetadata file) {
7590
EntityInfo fileInfo = new EntityInfo();
7691
fileInfo.setSize(file.getSize());

Diff for: src/main/java/com/onedatashare/scheduler/services/expanders/GDriveExpander.java

+9
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ public List<EntityInfo> expandedFileSystem(List<EntityInfo> userSelectedResource
7373
return fileInfoList;
7474
}
7575

76+
public List<EntityInfo> expandedDestFileSystem(String basePath) {
77+
Stack<File> fileListStack = new Stack<>();
78+
List<EntityInfo> destFilesList = new ArrayList<>();
79+
80+
googleDriveLister(fileListStack, destFilesList, "", "");
81+
82+
return destFilesList;
83+
}
84+
7685
private void googleDriveLister(Stack<File> fileListStack, List<EntityInfo> fileInfoList, String fileQuery, String parentFolderId) {
7786
FileList fileList;
7887
String pageToken = "";

Diff for: src/main/java/com/onedatashare/scheduler/services/expanders/HttpExpander.java

+17
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,23 @@ public List<EntityInfo> expandedFileSystem(List<EntityInfo> userSelectedResource
9494
return filesToSend;
9595
}
9696

97+
@SneakyThrows
98+
public List<EntityInfo> expandedDestFileSystem(String basePath) {
99+
List<EntityInfo> destFilesList = new ArrayList<>();
100+
Stack<Element> directoriesToTraverse = new Stack<>();
101+
if (basePath.isEmpty()) basePath = "/";
102+
103+
Document doc = Jsoup.connect(this.credential.getUri() + basePath).get();
104+
Elements links = doc.select("body a");
105+
for (Element elem : links) {
106+
//ignore dir, consider all files and add to list
107+
if (!elem.text().endsWith("/")) {
108+
destFilesList.add(fromElement(elem));
109+
}
110+
}
111+
return destFilesList;
112+
}
113+
97114
public EntityInfo fromElement(Element elem) throws IOException {
98115
EntityInfo fileInfo = new EntityInfo();
99116
URL url = new URL(elem.absUrl("href"));

0 commit comments

Comments
 (0)