Search in sources :

Example 1 with GoogleDrivePutParameters

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;
}
Also used : GoogleDrivePutParameters(org.talend.components.google.drive.runtime.utils.GoogleDrivePutParameters) Record(org.apache.avro.generic.GenericData.Record)

Example 2 with GoogleDrivePutParameters

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);
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) GoogleDrivePutParameters(org.talend.components.google.drive.runtime.utils.GoogleDrivePutParameters) Record(org.apache.avro.generic.GenericData.Record) IndexedRecord(org.apache.avro.generic.IndexedRecord)

Example 3 with GoogleDrivePutParameters

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);
    }
}
Also used : GoogleDrivePutParameters(org.talend.components.google.drive.runtime.utils.GoogleDrivePutParameters) GeneralSecurityException(java.security.GeneralSecurityException) ComponentException(org.talend.components.api.exception.ComponentException) IOException(java.io.IOException)

Aggregations

GoogleDrivePutParameters (org.talend.components.google.drive.runtime.utils.GoogleDrivePutParameters)3 Record (org.apache.avro.generic.GenericData.Record)2 IOException (java.io.IOException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 IndexedRecord (org.apache.avro.generic.IndexedRecord)1 ComponentException (org.talend.components.api.exception.ComponentException)1