use of org.talend.dataprep.api.service.command.preparation.LocatePreparation in project data-prep by Talend.
the class APIPreparationConversions method toEnrichedPreparation.
private EnrichedPreparation toEnrichedPreparation(PreparationMessage preparationMessage, EnrichedPreparation enrichedPreparation, ApplicationContext applicationContext) {
final SecurityProxy securityProxy = applicationContext.getBean(SecurityProxy.class);
// Add related dataset information
if (preparationMessage.getDataSetId() == null) {
return enrichedPreparation;
} else {
// get the dataset metadata
try {
// because dataset are not shared
securityProxy.asTechnicalUser();
final DataSetGetMetadata bean = applicationContext.getBean(DataSetGetMetadata.class, preparationMessage.getDataSetId());
final DataSetMetadata dataSetMetadata = bean.execute();
enrichedPreparation.setSummary(new EnrichedPreparation.DataSetMetadataSummary(dataSetMetadata));
} catch (Exception e) {
LOGGER.debug("error reading dataset metadata {} : {}", enrichedPreparation.getId(), e);
return enrichedPreparation;
} finally {
securityProxy.releaseIdentity();
}
}
// Add step ids
LinkedList<String> collected = new LinkedList<>();
preparationMessage.getSteps().stream().map(Step::getId).forEach(s -> {
if (s != null && (collected.isEmpty() || !collected.getLast().equals(s))) {
collected.add(s);
}
});
enrichedPreparation.setSteps(collected);
// Add folder information
final LocatePreparation command = applicationContext.getBean(LocatePreparation.class, enrichedPreparation.getId());
final Folder folder = command.execute();
enrichedPreparation.setFolder(folder);
return enrichedPreparation;
}
Aggregations