use of org.talend.components.api.exception.ComponentException 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.api.exception.ComponentException in project components by Talend.
the class GoogleDriveCreateRuntime method createFolder.
public void createFolder(RuntimeContainer container) {
try {
final GoogleDriveUtils utils = getDriveUtils();
String parentFolder = properties.parentFolder.getValue();
parentFolderId = properties.parentFolderAccessMethod.getValue().equals(AccessMethod.Id) ? parentFolder : utils.getFolderId(parentFolder, false);
newFolderId = utils.createFolder(parentFolderId, properties.newFolder.getValue());
} catch (IOException | GeneralSecurityException e) {
LOG.error(e.getLocalizedMessage());
throw new ComponentException(e);
}
}
use of org.talend.components.api.exception.ComponentException in project components by Talend.
the class XMLGregorianCalendarToDateTimeConverter method convertToAvro.
@Override
public Object convertToAvro(XMLGregorianCalendar xts) {
if (xts == null) {
return null;
}
MutableDateTime dateTime = new MutableDateTime();
try {
dateTime.setYear(xts.getYear());
dateTime.setMonthOfYear(xts.getMonth());
dateTime.setDayOfMonth(xts.getDay());
dateTime.setHourOfDay(xts.getHour());
dateTime.setMinuteOfHour(xts.getMinute());
dateTime.setSecondOfMinute(xts.getSecond());
dateTime.setMillisOfSecond(xts.getMillisecond());
DateTimeZone tz = DateTimeZone.forOffsetMillis(xts.getTimezone() * 60000);
if (tz != null) {
dateTime.setZoneRetainFields(tz);
}
return Long.valueOf(dateTime.getMillis());
} catch (IllegalArgumentException e) {
throw new ComponentException(e);
}
}
use of org.talend.components.api.exception.ComponentException in project components by Talend.
the class AzureStorageTableReader method start.
@Override
public boolean start() throws IOException {
String tableName = properties.tableName.getValue();
String filter = "";
if (properties.useFilterExpression.getValue()) {
filter = properties.filterExpression.generateCombinedFilterConditions();
LOGGER.debug(i18nMessages.getMessage("debug.FilterApplied", filter));
}
try {
TableQuery<DynamicTableEntity> partitionQuery;
if (filter.isEmpty()) {
partitionQuery = TableQuery.from(DynamicTableEntity.class);
} else {
partitionQuery = TableQuery.from(DynamicTableEntity.class).where(filter);
}
// Using execute will automatically and lazily follow the continuation tokens from page to page of results.
// So, we bypass the 1000 entities limit.
Iterable<DynamicTableEntity> entities = tableService.executeQuery(tableName, partitionQuery);
recordsIterator = entities.iterator();
if (recordsIterator.hasNext()) {
started = true;
result.totalCount++;
current = recordsIterator.next();
}
} catch (InvalidKeyException | URISyntaxException | StorageException e) {
LOGGER.error(e.getLocalizedMessage());
if (properties.dieOnError.getValue()) {
throw new ComponentException(e);
}
}
return started;
}
use of org.talend.components.api.exception.ComponentException in project components by Talend.
the class AzureStorageQueueWriter method write.
@Override
public void write(Object object) throws IOException {
String content;
if (object == null)
return;
cleanWrites();
result.totalCount++;
if (writeSchema == null) {
writeSchema = ((IndexedRecord) object).getSchema();
}
GenericIndexedRecordConverter factory = new GenericIndexedRecordConverter();
factory.setSchema(writeSchema);
IndexedRecord inputRecord = factory.convertToAvro((IndexedRecord) object);
Field msgContent = writeSchema.getField(AzureStorageQueueProperties.FIELD_MESSAGE_CONTENT);
int ttl = props.timeToLiveInSeconds.getValue();
int visibility = props.initialVisibilityDelayInSeconds.getValue();
if (msgContent == null) {
LOGGER.error(i18nMessages.getMessage("error.VacantMessage"));
if (props.dieOnError.getValue()) {
throw new ComponentException(new Exception(i18nMessages.getMessage("error.VacantMessage")));
}
} else {
content = (String) inputRecord.get(msgContent.pos());
messagesBuffer.add(new QueueMessage(new CloudQueueMessage(content), ttl, visibility));
}
if (messagesBuffer.size() >= MAX_MSG_TO_ENQUEUE) {
sendParallelMessages();
}
}
Aggregations