use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class PreparationUpdate method onExecute.
private HttpRequestBase onExecute(String id, Preparation preparation) {
try {
final byte[] preparationJSONValue = objectMapper.writeValueAsBytes(preparation);
final HttpPut preparationCreation = new HttpPut(preparationServiceUrl + "/preparations/" + id);
preparationCreation.setHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE);
preparationCreation.setEntity(new ByteArrayEntity(preparationJSONValue));
return preparationCreation;
} catch (JsonProcessingException e) {
throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
}
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class ActionsImport method registerBeanDefinitions.
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
// Create the annotation-based context
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, false);
AtomicInteger actionCount = new AtomicInteger(0);
scanner.setBeanNameGenerator((definition, beanRegistry) -> {
try {
final Class<?> clazz = Class.forName(definition.getBeanClassName());
return ACTION_BEAN_PREFIX + AnnotationUtils.findAnnotation(clazz, Action.class).value();
} catch (Exception e) {
// Rather unexpected, filter must have found and check the class earlier.
throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
} finally {
actionCount.incrementAndGet();
}
});
scanner.addIncludeFilter(new ActionFilter());
scanner.scan("org.talend.dataprep");
// Import scanned services in current registry
final String[] names = context.getBeanDefinitionNames();
for (String name : names) {
final BeanDefinition definition = context.getBeanDefinition(name);
registry.registerBeanDefinition(name, definition);
}
LOGGER.info("{} action(s) found.", actionCount.get());
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class DataSetContentStore method stream.
/**
* Similarly to {@link #get(DataSetMetadata)} returns the content of the data set but as a {@link Stream stream} of
* {@link DataSetRow rows} instead of JSON content.
*
* @param dataSetMetadata The {@link DataSetMetadata data set} to read rows from.
* @param limit A limit to pass to raw content supplier (use -1 for "no limit). Used as parameter to call
* {@link #get(DataSetMetadata, long)}.
* @return A valid <b>{@link DataSetRow}</b> stream.
*/
public Stream<DataSetRow> stream(DataSetMetadata dataSetMetadata, long limit) {
final InputStream inputStream = get(dataSetMetadata, limit);
final DataSetRowIterator iterator = new DataSetRowIterator(inputStream);
final Iterable<DataSetRow> rowIterable = () -> iterator;
Stream<DataSetRow> dataSetRowStream = StreamSupport.stream(rowIterable.spliterator(), false);
// make sure to close the original input stream when closing this one
AtomicLong tdpId = new AtomicLong(1);
final List<ColumnMetadata> columns = dataSetMetadata.getRowMetadata().getColumns();
final Analyzer<Analyzers.Result> analyzer = service.build(columns, AnalyzerService.Analysis.QUALITY);
dataSetRowStream = dataSetRowStream.filter(r -> !r.isEmpty()).map(r -> {
final String[] values = r.order(columns).toArray(DataSetRow.SKIP_TDP_ID);
analyzer.analyze(values);
return r;
}).map(// Mark invalid columns as detected by provided analyzer.
new InvalidMarker(columns, analyzer)).map(r -> {
//
r.setTdpId(tdpId.getAndIncrement());
return r;
}).onClose(() -> {
//
try {
inputStream.close();
} catch (Exception e) {
throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
}
});
return dataSetRowStream;
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class AESEncryption method encryptUriPassword.
/**
* Encrypt the password part of the URI if any and returns it.
*
* @param rawUri the URI that may contain a password in its user info part.
* @return the URI with its password part, if any, encrypted.
* @throws GeneralSecurityException In case of security-related issues.or encryption fails.
* @throws TDPException if rawUri is not a valid URI.
*/
public static String encryptUriPassword(final String rawUri) throws GeneralSecurityException {
try {
URI uri = new URI(rawUri);
UserInfo userInfo = extractCredentials(uri);
if (userInfo != null && userInfo.password != null) {
userInfo.password = encrypt(userInfo.password);
return setCredentials(uri, userInfo).toString();
} else {
return rawUri;
}
} catch (URISyntaxException e) {
throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
}
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class APIPreparationConversionsTest method shouldDealWithExceptionInDataSetGet.
@Test
public void shouldDealWithExceptionInDataSetGet() {
// given
final PreparationMessage preparation = getPreparationMessage("DS-1234");
when(applicationContext.getBean(eq(DataSetGet.class), any(Object[].class))).thenAnswer(i -> {
final DataSetGet mock = mock(DataSetGet.class);
when(mock.execute()).thenThrow(new TDPException(DataSetErrorCodes.DATASET_DOES_NOT_EXIST));
return mock;
});
// when
final EnrichedPreparation actual = conversionService.convert(preparation, EnrichedPreparation.class);
// then
assertNotNull(actual);
assertNull(actual.getSummary());
assertNull(actual.getFolder());
}
Aggregations