Search in sources :

Example 11 with TalendRuntimeException

use of org.talend.daikon.exception.TalendRuntimeException in project components by Talend.

the class NetSuiteOutputModuleProperties method afterMainSchema.

private void afterMainSchema() {
    try {
        Schema schema = main.schema.getValue();
        if (lastMainSchema != null) {
            // ignore this change to avoid unnecessary updating of schema for outgoing flow(s).
            if (schema.equals(lastMainSchema)) {
                return;
            }
            setupOutgoingSchema();
            refreshLayout(getForm(Form.MAIN));
            refreshLayout(getForm(Form.ADVANCED));
        }
        // Remember changed schema for next check
        lastMainSchema = schema;
    } catch (TalendRuntimeException e) {
        throw ComponentExceptions.asComponentExceptionWithValidationResult(e);
    }
}
Also used : TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException) Schema(org.apache.avro.Schema)

Example 12 with TalendRuntimeException

use of org.talend.daikon.exception.TalendRuntimeException in project components by Talend.

the class PropertiesControllerImpl method triggerOnProperty.

@Override
public // 
ResponseEntity<String> triggerOnProperty(// 
PropertyTrigger trigger, // 
String property, // 
String formName, UiSpecsPropertiesDto propertiesContainer) {
    Properties properties = propertiesHelpers.propertiesFromDto(propertiesContainer);
    String response;
    try {
        Properties updatedProperties;
        switch(trigger) {
            case VALIDATE:
                updatedProperties = componentService.validateProperty(property, properties);
                break;
            case BEFORE_ACTIVE:
                updatedProperties = componentService.beforePropertyActivate(property, properties);
                break;
            case BEFORE_PRESENT:
                updatedProperties = componentService.beforePropertyPresent(property, properties);
                break;
            case AFTER:
                updatedProperties = componentService.afterProperty(property, properties);
                break;
            default:
                throw new IllegalArgumentException("This enum does not contain this value: " + trigger);
        }
        response = jsonSerializationHelper.toJson(updatedProperties, formName, propertiesContainer.getDefinitionName());
    } catch (IllegalStateException e) {
        log.info("Tried to execute an undefined trigger. It show either a bug in the calling client or the definition" + " properties advertised a non-existent trigger", e);
        throw new UndefinedTriggerException(propertiesContainer.getDefinitionName(), property, trigger);
    } catch (Throwable throwable) {
        Exception exception = handleErrors(throwable);
        log.warn("Error validating property.", exception);
        // Letting common handler return a 500 error and correct message structure
        throw new TalendRuntimeException(CommonErrorCodes.UNEXPECTED_EXCEPTION, exception);
    }
    return new ResponseEntity<>(response, OK);
}
Also used : TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException) ResponseEntity(org.springframework.http.ResponseEntity) DatasetProperties(org.talend.components.common.dataset.DatasetProperties) DatastoreProperties(org.talend.components.common.datastore.DatastoreProperties) Properties(org.talend.daikon.properties.Properties) TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException)

Example 13 with TalendRuntimeException

use of org.talend.daikon.exception.TalendRuntimeException in project components by Talend.

the class ReaderDataProviderTest method testReaderDataProviderWithException.

@Test
public void testReaderDataProviderWithException() throws IOException {
    Reader<String> reader = mock(Reader.class);
    Consumer consumer = mock(Consumer.class);
    ReaderDataProvider<String> readerDataProvider = new ReaderDataProvider<>(reader, 100, consumer);
    // reader start throws an IOE
    when(reader.start()).thenThrow(new IOException());
    try {
        readerDataProvider.retrieveData();
        fail("the code above should have thrown an exception");
    } catch (TalendRuntimeException tre) {
        // expected exception
        verify(reader, times(1)).close();
    }
    // reader getCurrent throws an IOE
    reset(reader);
    when(reader.start()).thenReturn(true);
    when(reader.getCurrent()).thenThrow(new NoSuchElementException());
    try {
        readerDataProvider.retrieveData();
        fail("the code above should have thrown an exception");
    } catch (TalendRuntimeException tre) {
        // expected exception
        verify(reader, times(1)).close();
    }
    // reader close throws an IOE
    reset(reader);
    when(reader.start()).thenReturn(false);
    doThrow(new IOException()).when(reader).close();
    try {
        readerDataProvider.retrieveData();
        fail("the code above should have thrown an exception");
    } catch (TalendRuntimeException tre) {
    // expected exception
    }
}
Also used : TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException) Consumer(org.talend.daikon.java8.Consumer) IOException(java.io.IOException) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.Test)

Example 14 with TalendRuntimeException

use of org.talend.daikon.exception.TalendRuntimeException in project data-prep by Talend.

the class SimpleFilterService method build.

@Override
public Predicate<DataSetRow> build(String filterAsString, RowMetadata rowMetadata) {
    if (isEmpty(filterAsString)) {
        return r -> true;
    }
    try {
        ObjectMapper mapper = new ObjectMapper();
        final JsonNode root = mapper.reader().readTree(filterAsString);
        final Iterator<JsonNode> elements = root.elements();
        if (!elements.hasNext()) {
            throw new IllegalArgumentException("Malformed filter: " + filterAsString);
        } else {
            return buildFilter(root, rowMetadata);
        }
    } catch (Exception e) {
        throw new TalendRuntimeException(BaseErrorCodes.UNABLE_TO_PARSE_FILTER, e);
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) DateManipulator(org.talend.dataprep.date.DateManipulator) DateParser(org.talend.dataprep.transformation.actions.date.DateParser) LocalDateTime(java.time.LocalDateTime) LoggerFactory(org.slf4j.LoggerFactory) NumericHelper.isBigDecimal(org.talend.dataprep.util.NumericHelper.isBigDecimal) NumberUtils(org.apache.commons.lang.math.NumberUtils) AnalyzerService(org.talend.dataprep.quality.AnalyzerService) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) JsonNode(com.fasterxml.jackson.databind.JsonNode) ParseException(java.text.ParseException) BaseErrorCodes(org.talend.dataprep.BaseErrorCodes) DateTimeException(java.time.DateTimeException) TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException) Logger(org.slf4j.Logger) StringUtils.isEmpty(org.apache.commons.lang.StringUtils.isEmpty) Iterator(java.util.Iterator) Predicate(java.util.function.Predicate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Providers(org.talend.dataprep.transformation.actions.Providers) NumericHelper(org.talend.dataprep.util.NumericHelper) List(java.util.List) BigDecimalParser(org.talend.daikon.number.BigDecimalParser) Type(org.talend.dataprep.api.type.Type) DateTimeFormatter(java.time.format.DateTimeFormatter) ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ParseException(java.text.ParseException) DateTimeException(java.time.DateTimeException) TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException)

Example 15 with TalendRuntimeException

use of org.talend.daikon.exception.TalendRuntimeException in project data-prep by Talend.

the class DataSetRowIterator method next.

/**
 * @see Iterator#next()
 */
@Override
public DataSetRow next() {
    try {
        String currentFieldName = StringUtils.EMPTY;
        JsonToken nextToken;
        row.clear();
        while ((nextToken = parser.nextToken()) != JsonToken.END_OBJECT) {
            if (nextToken == null) {
                // End of input, return the current row.
                LOGGER.warn("Unexpected end of input for row {}.", row.values());
                return row;
            }
            switch(nextToken) {
                // DataSetRow fields
                case FIELD_NAME:
                    currentFieldName = parser.getText();
                    break;
                case VALUE_STRING:
                    setStringValue(currentFieldName, parser.getText());
                    break;
                case VALUE_NULL:
                    row.set(currentFieldName, "");
                    break;
                case VALUE_TRUE:
                case VALUE_FALSE:
                    if ("_deleted".equals(currentFieldName)) {
                        row.setDeleted(Boolean.parseBoolean(parser.getText()));
                    }
                    break;
                case VALUE_NUMBER_INT:
                case VALUE_NUMBER_FLOAT:
                    if (FlagNames.TDP_ID.equals(currentFieldName)) {
                        row.setTdpId(Long.parseLong(parser.getText()));
                    }
                    break;
                default:
                    // let's skip this unsupported token
                    break;
            }
        }
        parser.nextToken();
        return row;
    } catch (IOException e) {
        throw new TalendRuntimeException(BaseErrorCodes.UNABLE_TO_PARSE_JSON, e);
    }
}
Also used : TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException) JsonToken(com.fasterxml.jackson.core.JsonToken) IOException(java.io.IOException)

Aggregations

TalendRuntimeException (org.talend.daikon.exception.TalendRuntimeException)28 IndexedRecord (org.apache.avro.generic.IndexedRecord)10 IOException (java.io.IOException)8 Test (org.junit.Test)7 Pipeline (org.apache.beam.sdk.Pipeline)6 Schema (org.apache.avro.Schema)5 Path (org.apache.hadoop.fs.Path)5 ConvertToIndexedRecord (org.talend.components.adapter.beam.transform.ConvertToIndexedRecord)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 SimpleFileIOOutputProperties (org.talend.components.simplefileio.output.SimpleFileIOOutputProperties)4 BufferedWriter (java.io.BufferedWriter)3 OutputStream (java.io.OutputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 DateTimeException (java.time.DateTimeException)2 LocalDateTime (java.time.LocalDateTime)2 GenericRecord (org.apache.avro.generic.GenericRecord)2 StringUtils (org.apache.commons.lang.StringUtils)2 SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)2