use of com.google.api.services.drive.model.FileList in project local-data-aragopedia by aragonopendata.
the class GoogleDriveAPI method listOwnerFilesAfterDate.
/**
* Method to list files and folders of id account after date of parameter
*/
public List<File> listOwnerFilesAfterDate(String stringDateLastChange) {
SimpleDateFormat formatFullDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date dateLastChange = null;
try {
dateLastChange = formatFullDate.parse(stringDateLastChange);
} catch (ParseException e1) {
log.error("Error parse date in list", e1);
}
FileList result;
List<File> files = null;
try {
result = drive.files().list().setMaxResults(1000).execute();
files = result.getItems();
} catch (Exception e) {
log.error("Error list files", e);
}
if (files == null || files.size() == 0) {
log.error("No files found");
} else {
for (File file : files) {
if (file.getShared()) {
DateTime dateTime = file.getModifiedDate();
Date dateModifyFile = new Date(dateTime.getValue());
if (dateModifyFile.after(dateLastChange))
log.info("Title " + file.getTitle() + " id " + file.getId() + " DateTime " + formatFullDate.format(dateModifyFile));
}
}
}
return files;
}
use of com.google.api.services.drive.model.FileList in project local-data-aragopedia by aragonopendata.
the class GoogleDriveAPI method listOwnerFiles.
/**
* Method to list all files and folders of id account
*/
public List<File> listOwnerFiles() {
log.debug("init listOwnerFiles()");
List<File> result = new ArrayList<File>();
try {
com.google.api.services.drive.Drive.Files.List request = drive.files().list().setQ("trashed = false");
do {
try {
FileList files = request.execute();
result.addAll(files.getItems());
request.setPageToken(files.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 list files", e);
}
log.debug("end listOwnerFiles()");
return result;
}
use of com.google.api.services.drive.model.FileList in project camel by apache.
the class DriveFilesIntegrationTest method testList.
@Test
public void testList() throws Exception {
// upload a test file
File testFile = uploadTestFile();
FileList result = requestBody("direct://LIST", null);
assertNotNull("list result", result);
assertTrue(result.getItems().size() >= 1);
File testFile2 = uploadTestFile();
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("CamelGoogleDrive.maxResults", 1);
result = requestBodyAndHeaders("direct://LIST", null, headers);
assertNotNull("list result", result);
assertTrue(result.getItems().size() == 1);
// test paging the list
List<File> resultList = new ArrayList<File>();
String pageToken;
int i = 0;
do {
result = requestBodyAndHeaders("direct://LIST", null, headers);
resultList.addAll(result.getItems());
pageToken = result.getNextPageToken();
headers.put("CamelGoogleDrive.pageToken", pageToken);
i++;
} while (pageToken != null && pageToken.length() > 0 && i < 2);
// we should have 2 files in result (one file for each of the 2 pages)
assertTrue(resultList.size() == 2);
// they should be different files
assertFalse(resultList.get(0).getId().equals(resultList.get(1)));
}
use of com.google.api.services.drive.model.FileList in project camel by apache.
the class FilesConsumerIntegrationTest method testListConsumer.
@Test
public void testListConsumer() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
File testFile = uploadTestFile();
String fileId = testFile.getId();
assertMockEndpointsSatisfied();
FileList fileList = mock.getReceivedExchanges().get(0).getIn().getBody(com.google.api.services.drive.model.FileList.class);
assertTrue(fileInList(fileId, fileList));
}
use of com.google.api.services.drive.model.FileList in project Aegis by Decad3nce.
the class BackupGoogleAccountsActivity method getAegisFolder.
private static String getAegisFolder() {
Files.List request = null;
String folderID = null;
try {
request = service.files().list().setQ("mimeType= 'application/vnd.google-apps.folder' and title = 'aeGis Backup' and trashed = false");
} catch (IOException e) {
e.printStackTrace();
return null;
}
do {
FileList files;
try {
files = request.execute();
for (File file : files.getItems()) {
folderID = file.getId();
}
} catch (IOException e) {
e.printStackTrace();
return null;
}
} while (request.getPageToken() != null && request.getPageToken().length() > 0);
//Log.i(TAG, "FolderID: " + folderID);
return folderID;
}
Aggregations