Search in sources :

Example 1 with PreparationRepository

use of org.talend.dataprep.preparation.store.PreparationRepository 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;
}
Also used : PreparationRepository(org.talend.dataprep.preparation.store.PreparationRepository) Owner(org.talend.dataprep.api.share.Owner) Security(org.talend.dataprep.security.Security) ActionRegistry(org.talend.dataprep.transformation.pipeline.ActionRegistry) ActionDefinition(org.talend.dataprep.api.action.ActionDefinition)

Example 2 with PreparationRepository

use of org.talend.dataprep.preparation.store.PreparationRepository 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;
}
Also used : ImplicitParameters(org.talend.dataprep.transformation.actions.common.ImplicitParameters) StringUtils(org.apache.commons.lang.StringUtils) CREATE_NEW_COLUMN(org.talend.dataprep.transformation.actions.common.ActionsUtils.CREATE_NEW_COLUMN) BeanConversionService.fromBean(org.talend.dataprep.conversions.BeanConversionService.fromBean) LoggerFactory(org.slf4j.LoggerFactory) PreparationRepository(org.talend.dataprep.preparation.store.PreparationRepository) org.talend.dataprep.api.preparation(org.talend.dataprep.api.preparation) PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation) ScopeCategory(org.talend.dataprep.transformation.actions.category.ScopeCategory) BeanConversionService(org.talend.dataprep.conversions.BeanConversionService) Logger(org.slf4j.Logger) LocaleContextHolder.getLocale(org.springframework.context.i18n.LocaleContextHolder.getLocale) ActionRegistry(org.talend.dataprep.transformation.pipeline.ActionRegistry) Owner(org.talend.dataprep.api.share.Owner) Collectors(java.util.stream.Collectors) ApplicationContext(org.springframework.context.ApplicationContext) ActionForm(org.talend.dataprep.api.action.ActionForm) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Component(org.springframework.stereotype.Component) ActionDefinition(org.talend.dataprep.api.action.ActionDefinition) UserPreparation(org.talend.dataprep.preparation.service.UserPreparation) Security(org.talend.dataprep.security.Security) Collections(java.util.Collections) BeanConversionServiceWrapper(org.talend.dataprep.processor.BeanConversionServiceWrapper) PreparationRepository(org.talend.dataprep.preparation.store.PreparationRepository) ActionRegistry(org.talend.dataprep.transformation.pipeline.ActionRegistry) ActionDefinition(org.talend.dataprep.api.action.ActionDefinition) ActionForm(org.talend.dataprep.api.action.ActionForm)

Example 3 with PreparationRepository

use of org.talend.dataprep.preparation.store.PreparationRepository in project data-prep by Talend.

the class ActionNewColumnToggleCommonTest method shouldNotUpdateSteps.

@Test
public void shouldNotUpdateSteps() {
    // given
    final PreparationRepository repository = mock(PreparationRepository.class);
    final PreparationActions actions = mock(PreparationActions.class);
    final PersistentStep step = mock(PersistentStep.class);
    final Action action = mock(Action.class);
    List<Action> actionsList = new ArrayList<>();
    actionsList.add(action);
    when(step.id()).thenReturn("step-1");
    when(actions.getActions()).thenReturn(actionsList);
    when(action.getName()).thenReturn("action");
    when(repository.list(eq(PreparationActions.class))).thenReturn(Stream.of(actions));
    // Twice "action-1" to pass root preparation action filter.
    // same id
    when(actions.id()).thenReturn("actions-1", "actions-1", "actions-1");
    when(repository.list(eq(PersistentStep.class), any())).thenReturn(Stream.of(step));
    // when
    ActionNewColumnToggleCommon.upgradeActions(repository);
    // then
    verify(repository, times(1)).add(eq(actions));
    verify(repository, never()).add(eq(step));
    verify(step, never()).setContent(any());
}
Also used : PreparationRepository(org.talend.dataprep.preparation.store.PreparationRepository) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) Action(org.talend.dataprep.api.preparation.Action) ArrayList(java.util.ArrayList) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions) Test(org.junit.Test)

Example 4 with PreparationRepository

use of org.talend.dataprep.preparation.store.PreparationRepository in project data-prep by Talend.

the class ActionNewColumnToggleCommonTest method shouldNotUpdateRootStep.

@Test
public void shouldNotUpdateRootStep() {
    // given
    final PreparationRepository repository = mock(PreparationRepository.class);
    final PreparationActions actions = mock(PreparationActions.class);
    final PersistentStep step = mock(PersistentStep.class);
    final Action action = mock(Action.class);
    List<Action> actionsList = new ArrayList<>();
    actionsList.add(action);
    // Listed step is root step
    when(step.id()).thenReturn(Step.ROOT_STEP.id());
    when(actions.getActions()).thenReturn(actionsList);
    when(action.getName()).thenReturn("action");
    when(repository.list(eq(PreparationActions.class))).thenReturn(Stream.of(actions));
    when(actions.id()).thenReturn("actions-1", "actions-2");
    when(repository.list(eq(PersistentStep.class), any())).thenReturn(Stream.of(step));
    // when
    ActionNewColumnToggleCommon.upgradeActions(repository);
    // then
    verify(repository, times(1)).add(eq(actions));
    verify(repository, never()).add(eq(step));
    verify(step, never()).setContent(any());
}
Also used : PreparationRepository(org.talend.dataprep.preparation.store.PreparationRepository) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) Action(org.talend.dataprep.api.preparation.Action) ArrayList(java.util.ArrayList) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions) Test(org.junit.Test)

Example 5 with PreparationRepository

use of org.talend.dataprep.preparation.store.PreparationRepository in project data-prep by Talend.

the class ActionNewColumnToggleCommonTest method shouldUpdateSteps.

@Test
public void shouldUpdateSteps() {
    // given
    final PreparationRepository repository = mock(PreparationRepository.class);
    final PreparationActions actions = mock(PreparationActions.class);
    final PersistentStep step = mock(PersistentStep.class);
    final Action action = mock(Action.class);
    List<Action> actionsList = new ArrayList<>();
    actionsList.add(action);
    when(step.id()).thenReturn("step-1");
    when(actions.getActions()).thenReturn(actionsList);
    when(action.getName()).thenReturn("action");
    when(repository.list(eq(PreparationActions.class))).thenReturn(Stream.of(actions));
    // Twice "action-1" to pass root preparation action filter.
    when(actions.id()).thenReturn("actions-1", "actions-1", "actions-2");
    when(repository.list(eq(PersistentStep.class), any())).thenReturn(Stream.of(step));
    // when
    ActionNewColumnToggleCommon.upgradeActions(repository);
    // then
    verify(repository, times(1)).add(eq(actions));
    verify(repository, times(1)).add(eq(step));
    verify(step, times(1)).setContent(eq("actions-2"));
}
Also used : PreparationRepository(org.talend.dataprep.preparation.store.PreparationRepository) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) Action(org.talend.dataprep.api.preparation.Action) ArrayList(java.util.ArrayList) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions) Test(org.junit.Test)

Aggregations

PreparationRepository (org.talend.dataprep.preparation.store.PreparationRepository)5 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 Action (org.talend.dataprep.api.preparation.Action)3 PreparationActions (org.talend.dataprep.api.preparation.PreparationActions)3 PersistentStep (org.talend.dataprep.preparation.store.PersistentStep)3 ActionDefinition (org.talend.dataprep.api.action.ActionDefinition)2 Owner (org.talend.dataprep.api.share.Owner)2 Security (org.talend.dataprep.security.Security)2 ActionRegistry (org.talend.dataprep.transformation.pipeline.ActionRegistry)2 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 StringUtils (org.apache.commons.lang.StringUtils)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 ApplicationContext (org.springframework.context.ApplicationContext)1 LocaleContextHolder.getLocale (org.springframework.context.i18n.LocaleContextHolder.getLocale)1 Component (org.springframework.stereotype.Component)1