use of org.talend.dataprep.transformation.pipeline.ActionRegistry in project data-prep by Talend.
the class PreparationConversions method toStudioPreparation.
private PreparationSummary toStudioPreparation(Preparation source, PreparationSummary target, ApplicationContext applicationContext) {
if (target.getOwner() == null) {
final Security security = applicationContext.getBean(Security.class);
Owner owner = new Owner(security.getUserId(), security.getUserDisplayName(), StringUtils.EMPTY);
target.setOwner(owner);
}
final PreparationRepository preparationRepository = applicationContext.getBean(PreparationRepository.class);
final ActionRegistry actionRegistry = applicationContext.getBean(ActionRegistry.class);
// Get preparation actions
PreparationActions prepActions = preparationRepository.get(source.getHeadId(), PreparationActions.class);
if (prepActions != null) {
List<Action> actions = prepActions.getActions();
boolean allowDistributedRun = true;
for (Action action : actions) {
final ActionDefinition actionDefinition = actionRegistry.get(action.getName());
if (actionDefinition.getBehavior().contains(ActionDefinition.Behavior.FORBID_DISTRIBUTED)) {
// Disallow distributed run
allowDistributedRun = false;
break;
}
}
target.setAllowDistributedRun(allowDistributedRun);
}
return target;
}
use of org.talend.dataprep.transformation.pipeline.ActionRegistry in project data-prep by Talend.
the class PreparationConversions method toPreparationMessage.
private PreparationMessage toPreparationMessage(Preparation source, PreparationMessage target, ApplicationContext applicationContext) {
final PreparationRepository preparationRepository = applicationContext.getBean(PreparationRepository.class);
final ActionRegistry actionRegistry = applicationContext.getBean(ActionRegistry.class);
// Steps diff metadata
final List<StepDiff> diffs = //
source.getSteps().stream().filter(//
step -> !Step.ROOT_STEP.id().equals(step.id())).map(//
Step::getDiff).collect(toList());
target.setDiff(diffs);
// Actions
if (source.getHeadId() != null) {
// Get preparation actions
final String headId = source.getHeadId();
final Step head = preparationRepository.get(headId, Step.class);
if (head != null) {
final PreparationActions prepActions = preparationRepository.get(head.getContent(), PreparationActions.class);
if (prepActions != null) {
final List<Action> actions = prepActions.getActions();
target.setActions(prepActions.getActions());
// Allow distributed run
boolean allowDistributedRun = true;
for (Action action : actions) {
final ActionDefinition actionDefinition = actionRegistry.get(action.getName());
if (actionDefinition.getBehavior().contains(ActionDefinition.Behavior.FORBID_DISTRIBUTED)) {
allowDistributedRun = false;
break;
}
}
target.setAllowDistributedRun(allowDistributedRun);
// no need to have lock information (and may also break StandAlonePreparationParser...)
target.setLock(null);
// Actions metadata
if (actionRegistry == null) {
LOGGER.debug("No action metadata available, unable to serialize action metadata for preparation {}.", source.id());
} else {
List<ActionForm> actionDefinitions = //
actions.stream().map(a -> //
actionRegistry.get(a.getName()).adapt(//
ScopeCategory.from(a.getParameters().get(ImplicitParameters.SCOPE.getKey())))).map(//
a -> a.getActionForm(getLocale())).map(//
PreparationConversions::disallowColumnCreationChange).collect(Collectors.toList());
target.setMetadata(actionDefinitions);
}
}
} else {
LOGGER.warn("Head step #{} for preparation #{} does not exist.", headId, source.id());
target.setActions(Collections.emptyList());
target.setSteps(Collections.singletonList(Step.ROOT_STEP));
target.setMetadata(Collections.emptyList());
}
} else {
target.setActions(Collections.emptyList());
target.setSteps(Collections.singletonList(Step.ROOT_STEP));
target.setMetadata(Collections.emptyList());
}
return target;
}
use of org.talend.dataprep.transformation.pipeline.ActionRegistry in project data-prep by Talend.
the class PipelineTransformer method buildExecutable.
@Override
public ExecutableTransformer buildExecutable(DataSet input, Configuration configuration) {
final RowMetadata rowMetadata = input.getMetadata().getRowMetadata();
// prepare the fallback row metadata
RowMetadata fallBackRowMetadata = transformationRowMetadataUtils.getMatchingEmptyRowMetadata(rowMetadata);
final TransformerWriter writer = writerRegistrationService.getWriter(configuration.formatId(), configuration.output(), configuration.getArguments());
final ConfiguredCacheWriter metadataWriter = new ConfiguredCacheWriter(contentCache, DEFAULT);
final TransformationMetadataCacheKey metadataKey = cacheKeyGenerator.generateMetadataKey(configuration.getPreparationId(), configuration.stepId(), configuration.getSourceType());
final PreparationMessage preparation = configuration.getPreparation();
// function that from a step gives the rowMetadata associated to the previous/parent step
final Function<Step, RowMetadata> previousStepRowMetadataSupplier = s -> //
Optional.ofNullable(s.getParent()).map(//
id -> preparationUpdater.get(id)).orElse(null);
final Pipeline pipeline = //
Pipeline.Builder.builder().withAnalyzerService(//
analyzerService).withActionRegistry(//
actionRegistry).withPreparation(//
preparation).withActions(//
actionParser.parse(configuration.getActions())).withInitialMetadata(rowMetadata, //
configuration.volume() == SMALL).withMonitor(//
configuration.getMonitor()).withFilter(//
configuration.getFilter()).withLimit(//
configuration.getLimit()).withFilterOut(//
configuration.getOutFilter()).withOutput(//
() -> new WriterNode(writer, metadataWriter, metadataKey, fallBackRowMetadata)).withStatisticsAdapter(//
adapter).withStepMetadataSupplier(//
previousStepRowMetadataSupplier).withGlobalStatistics(//
configuration.isGlobalStatistics()).allowMetadataChange(//
configuration.isAllowMetadataChange()).build();
// wrap this transformer into an executable transformer
return new ExecutableTransformer() {
@Override
public void execute() {
try {
LOGGER.debug("Before transformation: {}", pipeline);
pipeline.execute(input);
} finally {
LOGGER.debug("After transformation: {}", pipeline);
}
if (preparation != null) {
final UpdatedStepVisitor visitor = new UpdatedStepVisitor(preparationUpdater);
pipeline.accept(visitor);
}
}
@Override
public void signal(Signal signal) {
pipeline.signal(signal);
}
};
}
Aggregations