use of com.google.api.services.drive.model.File in project local-data-aragopedia by aragonopendata.
the class GoogleDriveAPI method downloadChildFile.
/**
* Method to download file from folder
* @param path String with destination file
* @param child ChildReference to download
* @throws IOException
*/
private void downloadChildFile(String path, ChildReference child) throws IOException {
File file = drive.files().get(child.getId()).execute();
download(path, file);
}
use of com.google.api.services.drive.model.File in project local-data-aragopedia by aragonopendata.
the class GoogleDriveAPI method updateFile.
/**
* Method by update file
*
* @param name
* String name file
* @param fileContent
* content file
* @param newMimeType
* String with mime type
* @return boolean true if updated is success
*/
public boolean updateFile(String name, java.io.File fileContent, String newMimeType) {
File file = searchFile(name);
FileContent mediaContent = new FileContent(newMimeType, fileContent);
File updatedFile = null;
try {
updatedFile = drive.files().update(file.getId(), file, mediaContent).execute();
} catch (Exception e) {
log.error("Error actualizando fichero en google drive", e);
}
return (updatedFile != null);
}
use of com.google.api.services.drive.model.File in project local-data-aragopedia by aragonopendata.
the class GoogleDriveAPI method downloadFilesAfterDate.
/**
* Download files after a date
*
* @param path
* Path where download files
* @param stringDateLastChange
* String with a date
*/
public void downloadFilesAfterDate(String path, String stringDateLastChange) {
List<File> files = listOwnerFilesAfterDate(stringDateLastChange);
for (File file : files) {
try {
String downloadUrl = file.getExportLinks().get("text/csv");
HttpResponse resp = drive.getRequestFactory().buildGetRequest(new GenericUrl(downloadUrl)).execute();
InputStream input = resp.getContent();
java.io.File f = new java.io.File(path + java.io.File.separator + file.getTitle() + ".csv");
FileUtils.copyInputStreamToFile(input, f);
} catch (Exception e) {
log.error("Error decargando ficheros despues de una fecha en google drive", e);
}
}
}
use of com.google.api.services.drive.model.File 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;
}
use of com.google.api.services.drive.model.File in project local-data-aragopedia by aragonopendata.
the class GoogleDriveAPI method download.
private void download(String path, File file) throws IOException {
if (file.getShared()) {
String downloadUrl = file.getExportLinks().get("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
HttpResponse resp = drive.getRequestFactory().buildGetRequest(new GenericUrl(downloadUrl)).execute();
InputStream input = resp.getContent();
java.io.File f = new java.io.File(path + java.io.File.separator + file.getTitle() + "." + Prop.formatConfig);
FileUtils.copyInputStreamToFile(input, f);
}
}
Aggregations