use of org.talend.components.google.drive.runtime.utils.GoogleDrivePutParameters in project components by Talend.
the class GoogleDrivePutReader method start.
@Override
public boolean start() throws IOException {
super.start();
String localFilePath = properties.localFilePath.getValue();
String destinationFolderId = properties.destinationFolderAccessMethod.getValue().equals(AccessMethod.Id) ? properties.destinationFolder.getValue() : utils.getFolderId(properties.destinationFolder.getValue(), false);
GoogleDrivePutParameters p = new GoogleDrivePutParameters(destinationFolderId, properties.fileName.getValue(), properties.overwrite.getValue(), localFilePath);
sentFile = utils.putResource(p);
record = new Record(properties.schemaMain.schema.getValue());
record.put(0, java.nio.file.Files.readAllBytes(Paths.get(localFilePath)));
record.put(1, sentFile.getParents().get(0));
record.put(2, sentFile.getId());
result.totalCount++;
result.successCount++;
return true;
}
use of org.talend.components.google.drive.runtime.utils.GoogleDrivePutParameters in project components by Talend.
the class GoogleDrivePutWriter method write.
@Override
public void write(Object object) throws IOException {
if (object == null) {
return;
}
IndexedRecord input = (IndexedRecord) object;
Object data = input.get(0);
LOG.debug("data [{}] {}.", data.getClass().getCanonicalName(), data.toString());
byte[] bytes = null;
if (data instanceof byte[]) {
bytes = (byte[]) data;
} else {
bytes = data.toString().getBytes();
}
//
String destinationFolderId = properties.destinationFolderAccessMethod.getValue().equals(AccessMethod.Id) ? properties.destinationFolder.getValue() : utils.getFolderId(properties.destinationFolder.getValue(), false);
GoogleDrivePutParameters p = new GoogleDrivePutParameters(destinationFolderId, properties.fileName.getValue(), properties.overwrite.getValue(), bytes);
sentFile = utils.putResource(p);
//
IndexedRecord record = new Record(properties.schemaMain.schema.getValue());
record.put(0, bytes);
// TODO should return this values in outOfBandRecord
record.put(1, sentFile.getParents().get(0));
record.put(2, sentFile.getId());
cleanWrites();
result.successCount++;
result.totalCount++;
successfulWrites.add(record);
}
use of org.talend.components.google.drive.runtime.utils.GoogleDrivePutParameters in project components by Talend.
the class GoogleDrivePutRuntime method putFile.
private void putFile(RuntimeContainer container) {
try {
String destinationFolderId = properties.destinationFolderAccessMethod.getValue().equals(AccessMethod.Id) ? properties.destinationFolder.getValue() : getDriveUtils().getFolderId(properties.destinationFolder.getValue(), false);
GoogleDrivePutParameters p = new GoogleDrivePutParameters(destinationFolderId, properties.fileName.getValue(), properties.overwrite.getValue(), properties.localFilePath.getValue());
sentFile = getDriveUtils().putResource(p);
} catch (IOException | GeneralSecurityException e) {
LOG.error(e.getLocalizedMessage());
throw new ComponentException(e);
}
}
Aggregations