Search in sources :

Example 1 with CopyMode

use of org.talend.components.google.drive.copy.GoogleDriveCopyProperties.CopyMode in project components by Talend.

the class GoogleDriveCopyRuntime method copyProcess.

private void copyProcess(RuntimeContainer container) {
    CopyMode copyMode = properties.copyMode.getValue();
    String source = properties.source.getValue();
    String destinationFolder = properties.destinationFolder.getValue();
    String newName = properties.rename.getValue() ? properties.newName.getValue() : "";
    boolean deleteSourceFile = properties.deleteSourceFile.getValue();
    try {
        Drive drive = getDriveService();
        final GoogleDriveUtils utils = getDriveUtils();
        /* check for destination folder */
        String destinationFolderId = properties.destinationFolderAccessMethod.getValue().equals(AccessMethod.Id) ? destinationFolder : utils.getFolderId(destinationFolder, false);
        /* work on a fileName */
        if (CopyMode.File.equals(copyMode)) {
            /* check for managed resource */
            sourceId = properties.sourceAccessMethod.getValue().equals(AccessMethod.Id) ? source : utils.getFileId(source);
            destinationId = utils.copyFile(sourceId, destinationFolderId, newName, deleteSourceFile);
        } else {
            /* work on a folder */
            /* check for managed resource */
            sourceId = properties.sourceAccessMethod.getValue().equals(AccessMethod.Id) ? source : utils.getFolderId(source, false);
            if (newName.isEmpty()) {
                List<String> paths = utils.getExplodedPath(source);
                newName = paths.get(paths.size() - 1);
            }
            destinationId = utils.copyFolder(sourceId, destinationFolderId, newName);
        }
    } catch (IOException | GeneralSecurityException e) {
        LOG.error(e.getLocalizedMessage());
        throw new ComponentException(e);
    }
}
Also used : CopyMode(org.talend.components.google.drive.copy.GoogleDriveCopyProperties.CopyMode) GeneralSecurityException(java.security.GeneralSecurityException) ComponentException(org.talend.components.api.exception.ComponentException) Drive(com.google.api.services.drive.Drive) IOException(java.io.IOException)

Example 2 with CopyMode

use of org.talend.components.google.drive.copy.GoogleDriveCopyProperties.CopyMode in project components by Talend.

the class GoogleDriveCopyReader method start.

@Override
public boolean start() throws IOException {
    super.start();
    CopyMode copyMode = properties.copyMode.getValue();
    String source = properties.source.getValue();
    String destinationFolder = properties.destinationFolder.getValue();
    String newName = properties.rename.getValue() ? properties.newName.getValue() : "";
    boolean deleteSourceFile = properties.deleteSourceFile.getValue();
    /* check for destination folder */
    String destinationFolderId = properties.destinationFolderAccessMethod.getValue().equals(AccessMethod.Id) ? destinationFolder : utils.getFolderId(destinationFolder, false);
    /* work on a fileName */
    if (CopyMode.File.equals(copyMode)) {
        /* check for managed resource */
        sourceId = properties.sourceAccessMethod.getValue().equals(AccessMethod.Id) ? source : utils.getFileId(source);
        destinationId = utils.copyFile(sourceId, destinationFolderId, newName, deleteSourceFile);
    } else {
        /* work on a folder */
        /* check for managed resource */
        sourceId = properties.sourceAccessMethod.getValue().equals(AccessMethod.Id) ? source : utils.getFolderId(source, false);
        if (newName.isEmpty()) {
            List<String> paths = utils.getExplodedPath(source);
            newName = paths.get(paths.size() - 1);
        }
        destinationId = utils.copyFolder(sourceId, destinationFolderId, newName);
    }
    // 
    record = new Record(properties.schemaMain.schema.getValue());
    record.put(0, sourceId);
    record.put(1, destinationId);
    result.totalCount++;
    result.successCount++;
    return true;
}
Also used : CopyMode(org.talend.components.google.drive.copy.GoogleDriveCopyProperties.CopyMode) Record(org.apache.avro.generic.GenericData.Record)

Aggregations

CopyMode (org.talend.components.google.drive.copy.GoogleDriveCopyProperties.CopyMode)2 Drive (com.google.api.services.drive.Drive)1 IOException (java.io.IOException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 Record (org.apache.avro.generic.GenericData.Record)1 ComponentException (org.talend.components.api.exception.ComponentException)1