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