use of org.talend.dataprep.api.service.api.EnrichedPreparation 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;
}
use of org.talend.dataprep.api.service.api.EnrichedPreparation in project data-prep by Talend.
the class APIPreparationConversionsTest method shouldNotEnrichPreparationWithDataset.
@Test
public void shouldNotEnrichPreparationWithDataset() {
// given
final PreparationMessage preparation = getPreparationMessage(null);
// when
final EnrichedPreparation actual = conversionService.convert(preparation, EnrichedPreparation.class);
// then
assertNotNull(actual);
assertNull(actual.getSummary());
assertNull(actual.getFolder());
}
use of org.talend.dataprep.api.service.api.EnrichedPreparation in project data-prep by Talend.
the class APIPreparationConversionsTest method shouldDealWithRepeatedStepIds.
@Test
public void shouldDealWithRepeatedStepIds() {
// given
DataSetMetadata metadata = getDataSetMetadata("super dataset", 1001L);
setupHystrixCommand(DataSetGetMetadata.class, metadata);
final PreparationMessage preparation = getPreparationMessage(metadata.getId());
preparation.setSteps(asList(Step.ROOT_STEP, Step.ROOT_STEP));
Folder folder = getFolder("F-753854");
setupHystrixCommand(LocatePreparation.class, folder);
// when
final EnrichedPreparation actual = conversionService.convert(preparation, EnrichedPreparation.class);
// then
assertEquals(1, actual.getSteps().size());
assertEquals(Step.ROOT_STEP.id(), actual.getSteps().get(0));
}
Aggregations