use of com.google.api.services.drive.model.User in project components by Talend.
the class GoogleDriveDataSource method validate.
@Override
public ValidationResult validate(RuntimeContainer container) {
ValidationResult vr = new ValidationResultMutable(Result.OK);
// check for Connection attributes
if (StringUtils.isEmpty(serviceAccountFile)) {
vr = new ValidationResultMutable(Result.ERROR).setMessage("Service Account JSON File cannot be empty.");
return vr;
}
try {
// make a dummy call to check drive's connection..
User u = getDriveService().about().get().setFields("user").execute().getUser();
LOG.debug("[validate] Testing User Properties: {}.", u);
} catch (Exception ex) {
LOG.error("[validate] {}.", ex.getMessage());
vr = new ValidationResultMutable(Result.ERROR).setMessage(ex.getMessage());
return vr;
}
return ValidationResult.OK;
}
use of com.google.api.services.drive.model.User in project components by Talend.
the class GoogleDriveRuntime method validateConnection.
public ValidationResult validateConnection(GoogleDriveConnectionProperties connectionProperties) {
if ((OAuthMethod.InstalledApplicationWithIdAndSecret.equals(connectionProperties.oAuthMethod.getValue()) || OAuthMethod.InstalledApplicationWithJSON.equals(connectionProperties.oAuthMethod.getValue())) && container == null) {
cleanupCredentialsStore(getDatastoreFile(connectionProperties).toPath().resolve("StoredCredential"));
}
ValidationResultMutable vr = new ValidationResultMutable(validateConnectionProperties(connectionProperties));
if (Result.ERROR.equals(vr.getStatus())) {
return vr;
}
try {
// make a dummy call to check drive's connection..
User u = getDriveService().about().get().setFields("user").execute().getUser();
LOG.debug("[validateConnection] Testing User Properties: {}.", u);
} catch (Exception ex) {
LOG.error("[validateConnection] {}.", ex.getMessage());
vr.setStatus(Result.ERROR);
vr.setMessage(ex.getMessage());
return vr;
}
vr.setStatus(Result.OK);
vr.setMessage(messages.getMessage("message.connectionSuccessful"));
return vr;
}
use of com.google.api.services.drive.model.User in project components by Talend.
the class GoogleDriveDataSourceTest method testValidate.
@Test
public void testValidate() throws Exception {
dataSource.initialize(container, inputProperties);
assertEquals(Result.ERROR, dataSource.validate(container).getStatus());
dataSource = spy(dataSource);
Drive drive = mock(Drive.class, RETURNS_DEEP_STUBS);
GoogleDriveUtils utils = mock(GoogleDriveUtils.class, RETURNS_DEEP_STUBS);
doReturn(drive).when(dataSource).getDriveService();
doReturn(utils).when(dataSource).getDriveUtils();
inputProperties.getDatasetProperties().getDatastoreProperties().serviceAccountJSONFile.setValue("service.json");
dataSource.initialize(container, inputProperties);
About about = new About();
User user = new User();
user.setEmailAddress("test@example.org");
about.setUser(user);
when(drive.about().get().setFields(anyString()).execute()).thenReturn(about);
assertEquals(Result.OK, dataSource.validate(container).getStatus());
}
use of com.google.api.services.drive.model.User in project OpenRefine by OpenRefine.
the class GDataImportingController method listSpreadsheets.
private void listSpreadsheets(Drive drive, JsonGenerator writer) throws IOException {
com.google.api.services.drive.Drive.Files.List files = drive.files().list();
files.setQ("mimeType = 'application/vnd.google-apps.spreadsheet'");
files.setFields("nextPageToken, files(id, name, webViewLink, owners, modifiedTime)");
FileList fileList = files.execute();
for (File entry : fileList.getFiles()) {
writer.writeStartObject();
writer.writeStringField("docId", entry.getId());
writer.writeStringField("docLink", entry.getWebViewLink());
writer.writeStringField("docSelfLink", entry.getWebViewLink());
writer.writeStringField("title", entry.getName());
writer.writeStringField("type", "spreadsheet");
com.google.api.client.util.DateTime updated = entry.getModifiedTime();
if (updated != null) {
writer.writeStringField("updated", updated.toString());
}
writer.writeArrayFieldStart("authors");
for (User user : entry.getOwners()) {
writer.writeString(user.getDisplayName());
}
writer.writeEndArray();
writer.writeEndObject();
}
}
Aggregations