Search in sources :

Example 26 with ComponentException

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);
    }
}
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 27 with ComponentException

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

Example 28 with ComponentException

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);
    }
}
Also used : ComponentException(org.talend.components.api.exception.ComponentException) MutableDateTime(org.joda.time.MutableDateTime) DateTimeZone(org.joda.time.DateTimeZone)

Example 29 with ComponentException

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;
}
Also used : DynamicTableEntity(com.microsoft.azure.storage.table.DynamicTableEntity) ComponentException(org.talend.components.api.exception.ComponentException) URISyntaxException(java.net.URISyntaxException) InvalidKeyException(java.security.InvalidKeyException) StorageException(com.microsoft.azure.storage.StorageException)

Example 30 with ComponentException

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();
    }
}
Also used : Field(org.apache.avro.Schema.Field) CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) IndexedRecord(org.apache.avro.generic.IndexedRecord) GenericIndexedRecordConverter(org.talend.components.common.runtime.GenericIndexedRecordConverter) ComponentException(org.talend.components.api.exception.ComponentException) CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) URISyntaxException(java.net.URISyntaxException) StorageException(com.microsoft.azure.storage.StorageException) ComponentException(org.talend.components.api.exception.ComponentException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException)

Aggregations

ComponentException (org.talend.components.api.exception.ComponentException)101 URL (java.net.URL)32 MalformedURLException (java.net.MalformedURLException)30 JarRuntimeInfo (org.talend.components.api.component.runtime.JarRuntimeInfo)27 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)17 InvalidKeyException (java.security.InvalidKeyException)14 Schema (org.apache.avro.Schema)14 URISyntaxException (java.net.URISyntaxException)12 StorageException (com.microsoft.azure.storage.StorageException)11 NamedThing (org.talend.daikon.NamedThing)11 ValidationResult (org.talend.daikon.properties.ValidationResult)10 SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)10 IndexedRecord (org.apache.avro.generic.IndexedRecord)8 Test (org.junit.Test)8 SimpleNamedThing (org.talend.daikon.SimpleNamedThing)8 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)6 GeneralSecurityException (java.security.GeneralSecurityException)5 JDBCSource (org.talend.components.jdbc.runtime.JDBCSource)5 TJDBCInputDefinition (org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition)5