Search in sources :

Example 11 with PersistentPreparation

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

the class PreparationEventUtilTest method shouldUpdateDataSetName.

@Test
public void shouldUpdateDataSetName() {
    // given
    final DataSetMetadata metadata = new DataSetMetadata();
    metadata.setId("ds-1234");
    metadata.setName("My updated name");
    final PersistentPreparation preparation = mock(PersistentPreparation.class);
    when(preparationRepository.list(eq(PersistentPreparation.class), eq(TqlBuilder.eq("dataSetId", "ds-1234")))).thenReturn(Stream.of(preparation), Stream.of(preparation));
    when(datasetClient.getDataSetMetadata(eq("ds-1234"))).thenReturn(metadata);
    // when
    preparationEventUtil.performUpdateEvent(metadata.getId());
    // then
    verify(preparation, times(1)).setDataSetName(eq("My updated name"));
}
Also used : PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Test(org.junit.Test)

Example 12 with PersistentPreparation

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

the class SetStepRowMetadataTest method makePersistentPreparation.

private PersistentPreparation makePersistentPreparation(String id) {
    PersistentPreparation preparation = new PersistentPreparation();
    preparation.setId(id);
    return preparation;
}
Also used : PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation)

Example 13 with PersistentPreparation

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

the class PreparationService method addPreparationAction.

public void addPreparationAction(final String preparationId, final AppendStep appendStep) {
    PersistentPreparation preparation = preparationRepository.get(preparationId, PersistentPreparation.class);
    List<Action> actions = getVersionedAction(preparation, HEAD);
    StepDiff actionCreatedColumns = stepDiffDelegate.computeCreatedColumns(preparation.getRowMetadata(), buildActions(actions), buildActions(appendStep.getActions()));
    appendStep.setDiff(actionCreatedColumns);
    checkActionStepConsistency(appendStep);
    appendStepToHead(preparation, appendStep);
    LOGGER.debug("Added action to preparation.");
    if (auditService.isActive()) {
        auditService.auditPreparationAddStep(preparationId, appendStep.getActions().stream().collect(toMap(Action::getName, Action::getParameters)));
    }
}
Also used : RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) Action(org.talend.dataprep.api.preparation.Action) StepDiff(org.talend.dataprep.api.preparation.StepDiff) PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation)

Example 14 with PersistentPreparation

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

the class PreparationService method getPreparationDetails.

/**
 * Return a preparation details.
 *
 * @param id the wanted preparation id.
 * @param stepId the optional step id.
 * @return the preparation details.
 */
public PreparationDTO getPreparationDetails(String id, String stepId) {
    LOGGER.debug("Get content of preparation details for #{}.", id);
    final PersistentPreparation preparation = preparationRepository.get(id, PersistentPreparation.class);
    if (preparation == null) {
        throw new TDPException(PreparationErrorCodes.PREPARATION_DOES_NOT_EXIST, build().put(ID, id));
    }
    ensurePreparationConsistency(preparation);
    // specify the step id if provided
    if (!StringUtils.equals(HEAD, stepId)) {
        // just make sure the step does exist
        if (Step.ROOT_STEP.id().equals(stepId)) {
            preparation.setSteps(Collections.singletonList(Step.ROOT_STEP.id()));
            preparation.setHeadId(Step.ROOT_STEP.id());
        } else if (preparationRepository.exist(PersistentStep.class, eq(ID, stepId))) {
            preparation.setSteps(preparationUtils.listStepsIds(stepId, preparationRepository));
            preparation.setHeadId(stepId);
        } else {
            throw new TDPException(PREPARATION_STEP_DOES_NOT_EXIST, build().put(ID, preparation).put(STEP_ID, stepId));
        }
    }
    final PreparationDTO details = beanConversionService.convert(preparation, PreparationDTO.class);
    LOGGER.debug("returning details for {} -> {}", id, details);
    return details;
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation)

Example 15 with PersistentPreparation

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

the class PreparationService method deleteAction.

/**
 * Delete a step in a preparation.<br/>
 * STD : Step To Delete <br/>
 * <br/>
 * <ul>
 * <li>1. Extract the actions from STD (excluded) to the head. The actions list contains all the actions from the
 * STD's child to the head.</li>
 * <li>2. Filter the actions that apply on a column created by the step to delete. Those steps will be removed
 * too.</li>
 * <li>2bis. Change the actions that apply on columns whose id is higher than the STD last created column id. The
 * created columns ids after
 * the STD are shifted.</li>
 * <li>3. Set preparation head to STD's parent, so STD will be excluded</li>
 * <li>4. Append each action after the new preparation head</li>
 * </ul>
 *
 * @param id the preparation id.
 * @param stepToDeleteId the step id to delete.
 */
public void deleteAction(final String id, final String stepToDeleteId) {
    if (Step.ROOT_STEP.getId().equals(stepToDeleteId)) {
        throw new TDPException(PREPARATION_ROOT_STEP_CANNOT_BE_DELETED);
    }
    final PersistentPreparation preparation = lockPreparation(id);
    try {
        deleteAction(preparation, stepToDeleteId);
        auditService.auditPreparationDeleteStep(preparation.getId(), preparation.getName(), stepToDeleteId);
    } finally {
        unlockPreparation(id);
    }
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation)

Aggregations

PersistentPreparation (org.talend.dataprep.preparation.store.PersistentPreparation)25 Test (org.junit.Test)8 TDPException (org.talend.dataprep.exception.TDPException)7 PersistentStep (org.talend.dataprep.preparation.store.PersistentStep)7 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)5 FolderEntry (org.talend.dataprep.api.folder.FolderEntry)5 Action (org.talend.dataprep.api.preparation.Action)5 Preparation (org.talend.dataprep.api.preparation.Preparation)5 PreparationDTO (org.talend.dataprep.api.preparation.PreparationDTO)5 Step (org.talend.dataprep.api.preparation.Step)5 ArrayList (java.util.ArrayList)4 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)4 PreparationActions (org.talend.dataprep.api.preparation.PreparationActions)4 StepDiff (org.talend.dataprep.api.preparation.StepDiff)4 StepRowMetadata (org.talend.dataprep.api.preparation.StepRowMetadata)4 Collections (java.util.Collections)3 List (java.util.List)3 Map (java.util.Map)3 Collectors.toList (java.util.stream.Collectors.toList)3 StringUtils (org.apache.commons.lang3.StringUtils)3