use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class FileSystemFolderRepository method children.
@Override
public Stream<Folder> children(String parentId) {
final FolderPath parentDpPath = fromId(parentId);
try {
Path folderPath;
if (parentDpPath != null) {
folderPath = pathsConverter.toPath(parentDpPath);
} else {
folderPath = pathsConverter.getRootFolder();
}
Stream<Folder> children;
if (Files.notExists(folderPath)) {
children = Stream.empty();
} else {
children = //
Files.list(folderPath).map(p -> toFolderIfDirectory(p, security.getUserId())).filter(Objects::nonNull);
}
return children;
} catch (IOException e) {
throw new TDPException(UNABLE_TO_LIST_FOLDER_CHILDREN, e, build().put("path", parentDpPath == null ? null : parentDpPath.serializeAsString()));
}
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class PreparationExportStrategy method performPreparation.
public void performPreparation(final ExportParameters parameters, final OutputStream outputStream) {
final String stepId = parameters.getStepId();
final String preparationId = parameters.getPreparationId();
final String formatName = parameters.getExportType();
final PreparationMessage preparation = getPreparation(preparationId, stepId);
final String dataSetId = preparation.getDataSetId();
final ExportFormat format = getFormat(parameters.getExportType());
// get the dataset content (in an auto-closable block to make sure it is properly closed)
boolean releasedIdentity = false;
// Allow get dataset and get dataset metadata access whatever share status is
securityProxy.asTechnicalUser();
final DataSetGet dataSetGet = applicationContext.getBean(DataSetGet.class, dataSetId, false, true);
final DataSetGetMetadata dataSetGetMetadata = applicationContext.getBean(DataSetGetMetadata.class, dataSetId);
try (InputStream datasetContent = dataSetGet.execute()) {
try (JsonParser parser = mapper.getFactory().createParser(new InputStreamReader(datasetContent, UTF_8))) {
// head is not allowed as step id
final String version = getCleanStepId(preparation, stepId);
// Create dataset
final DataSet dataSet = mapper.readerFor(DataSet.class).readValue(parser);
dataSet.setMetadata(dataSetGetMetadata.execute());
// All good, can already release identity
securityProxy.releaseIdentity();
releasedIdentity = true;
// get the actions to apply (no preparation ==> dataset export ==> no actions)
final String actions = getActions(preparationId, version);
final TransformationCacheKey key = //
cacheKeyGenerator.generateContentKey(//
dataSetId, //
preparationId, //
version, //
formatName, //
parameters.getFrom(), //
parameters.getArguments(), //
parameters.getFilter());
LOGGER.debug("Cache key: " + key.getKey());
LOGGER.debug("Cache key details: " + key.toString());
try (final TeeOutputStream tee = new TeeOutputStream(outputStream, contentCache.put(key, ContentCache.TimeToLive.DEFAULT))) {
final Configuration configuration = //
Configuration.builder().args(//
parameters.getArguments()).outFilter(//
rm -> filterService.build(parameters.getFilter(), rm)).sourceType(parameters.getFrom()).format(//
format.getName()).actions(//
actions).preparation(//
preparation).stepId(//
version).volume(//
Configuration.Volume.SMALL).output(//
tee).limit(//
limit).build();
factory.get(configuration).buildExecutable(dataSet, configuration).execute();
tee.flush();
} catch (Throwable e) {
// NOSONAR
contentCache.evict(key);
throw e;
}
}
} catch (TDPException e) {
throw e;
} catch (Exception e) {
throw new TDPException(TransformationErrorCodes.UNABLE_TO_TRANSFORM_DATASET, e);
} finally {
if (!releasedIdentity) {
// Release identity in case of error.
securityProxy.releaseIdentity();
}
}
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class SaveAsyncExecution method init.
@PostConstruct
public void init() {
execute(() -> {
try {
final HttpPost post = new HttpPost(remoteRepositoryUrl + "/executions");
post.setHeader(new BasicHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE));
final StringWriter executionAsString = new StringWriter();
mapper.writerFor(AsyncExecution.class).writeValue(executionAsString, execution);
post.setEntity(new StringEntity(executionAsString.toString()));
return post;
} catch (IOException e) {
throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
}
});
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class CommandHelper method toPublisher.
/**
* Return a Publisher of type T out of the the hystrix command.
*
* @param clazz the wanted stream type.
* @param mapper the object mapper used to parse objects.
* @param command the hystrix command to deal with.
* @param <T> the type of objects to stream.
* @return a Publisher<T></T> out of the hystrix command response body.
*/
public static <T> Publisher<T> toPublisher(final Class<T> clazz, final ObjectMapper mapper, final HystrixCommand<InputStream> command) {
AtomicInteger count = new AtomicInteger(0);
return Flux.create(sink -> {
final Observable<InputStream> observable = command.toObservable();
observable.map(i -> {
try {
return mapper.readerFor(clazz).<T>readValues(i);
} catch (IOException e) {
throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
}
}).doOnCompleted(//
() -> LOGGER.debug("Completed command '{}' (emits '{}') with '{}' records.", command.getClass().getName(), clazz.getName(), count.get())).toBlocking().forEach(s -> {
while (s.hasNext()) {
sink.next(s.next());
count.incrementAndGet();
}
sink.complete();
});
}, FluxSink.OverflowStrategy.BUFFER);
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class DataSetGetMetadata method configureLimitedDataset.
private void configureLimitedDataset(final String dataSetId) {
execute(() -> new HttpGet(datasetServiceUrl + "/datasets/" + dataSetId + "/metadata"));
on(HttpStatus.OK).then((req, res) -> {
try {
final DataSet dataSet = objectMapper.readerFor(DataSet.class).readValue(res.getEntity().getContent());
return dataSet.getMetadata();
} catch (IOException e) {
throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
} finally {
req.releaseConnection();
}
});
}
Aggregations