use of com.google.api.services.drive.model.ChildReference in project local-data-aragopedia by aragonopendata.
the class GoogleDriveAPI method downloadFolderFiles.
/**
* Method to download folder files
* @param path String with destination path
* @param folderId String with id folder
* @throws IOException
*/
public void downloadFolderFiles(String path, String folderId) throws IOException {
List<ChildReference> listErrors = new ArrayList<>();
List<ChildReference> list = listFolderFiles(folderId);
FileUtils.deleteDirectory(new java.io.File(path));
for (ChildReference child : list) {
try {
downloadChildFile(path, child);
} catch (Exception e) {
log.error("Error en downloadFolderFiles with " + child, e);
listErrors.add(child);
}
}
int index = 0;
int numErrors = 0;
while (listErrors.size() > 0) {
ChildReference child = listErrors.get(index);
try {
downloadChildFile(path, child);
listErrors.remove(child);
numErrors = 0;
} catch (Exception e) {
log.error("Error en downloadFolderFiles with " + child, e);
listErrors.add(child);
if (numErrors != 0) {
numErrors++;
} else if (numErrors > 10) {
listErrors.remove(child);
numErrors = 0;
}
}
}
}
use of com.google.api.services.drive.model.ChildReference in project local-data-aragopedia by aragonopendata.
the class GoogleDriveAPI method listFolderFiles.
/**
* Method by list files into a folder
*
* @param folderId
* String id folder
* @return List with files
*/
public List<ChildReference> listFolderFiles(String folderId) {
List<ChildReference> result = new ArrayList<ChildReference>();
try {
com.google.api.services.drive.Drive.Children.List request = drive.children().list(folderId);
do {
try {
ChildList children = request.execute();
result.addAll(children.getItems());
request.setPageToken(children.getNextPageToken());
} catch (Exception e) {
System.out.println("An error occurred: " + e);
request.setPageToken(null);
}
} while (request.getPageToken() != null && request.getPageToken().length() > 0);
} catch (Exception e) {
log.error("Error buscando ficheros en una carpeta en google drive", e);
}
return result;
}
use of com.google.api.services.drive.model.ChildReference in project local-data-aragopedia by aragonopendata.
the class GoogleDriveAPI method searchFile.
/**
* Method to list all files and folders of id account
*/
public File searchFile(String name) {
log.debug("init listOwnerFiles()");
// FileList result;
List<ChildReference> list = listFolderFiles(Prop.idParentFolder);
File file = null;
for (ChildReference child : list) {
try {
file = drive.files().get(child.getId()).execute();
if (file != null) {
if (file.getShared() == true && file.getTitle().contains(name)) {
break;
}
}
} catch (IOException e) {
log.error("Error read file " + name + " in google Drive API", e);
}
}
// com.google.api.services.drive.Drive.Files.List request = null;
// try {
// request = drive.files().list().setMaxResults(1000);
// result = request.execute();
// files.addAll(result.getItems());
//
// } catch (Exception e) {
// log.error("Error list files", e);
// }
// if (files == null || files.size() == 0) {
// log.error("No files found");
// } else {
// log.debug("Files:\n");
// for (File fileAux : files) {
// if (fileAux.getShared() == true && fileAux.getTitle().contains(name)) {
// file = fileAux;
// break;
// }
// }
// }
log.debug("end listOwnerFiles()");
return file;
}
Aggregations