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);
}
}
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;
}
Aggregations