Search in sources :

Example 1 with MAX_VALUE

use of java.lang.Integer.MAX_VALUE in project data-prep by Talend.

the class PreparationService method updateAction.

/**
 * Update a step in a preparation <b>Strategy</b><br/>
 * The goal here is to rewrite the preparation history from 'the step to modify' (STM) to the head, with STM
 * containing the new action.<br/>
 * <ul>
 * <li>1. Extract the actions from STM (excluded) to the head</li>
 * <li>2. Insert the new actions before the other extracted actions. The actions list contains all the actions from
 * the <b>NEW</b> STM to the head</li>
 * <li>3. Set preparation head to STM's parent, so STM will be excluded</li>
 * <li>4. Append each action (one step is created by action) after the new preparation head</li>
 * </ul>
 */
public void updateAction(final String preparationId, final String stepToModifyId, final AppendStep newStep) {
    checkActionStepConsistency(newStep);
    LOGGER.debug("Modifying actions in preparation #{}", preparationId);
    final Preparation preparation = lockPreparation(preparationId);
    try {
        LOGGER.debug("Current head for preparation #{}: {}", preparationId, preparation.getHeadId());
        // Get steps from "step to modify" to the head
        // throws an exception if stepId is not in
        final List<String> steps = extractSteps(preparation, stepToModifyId);
        // the preparation
        LOGGER.debug("Rewriting history for {} steps.", steps.size());
        // Extract created columns ids diff info
        final Step stm = getStep(stepToModifyId);
        final List<String> originalCreatedColumns = stm.getDiff().getCreatedColumns();
        final List<String> updatedCreatedColumns = newStep.getDiff().getCreatedColumns();
        final List<String> deletedColumns = // columns that the step was creating but
        originalCreatedColumns.stream().filter(id -> !updatedCreatedColumns.contains(id)).collect(toList());
        final int columnsDiffNumber = updatedCreatedColumns.size() - originalCreatedColumns.size();
        final int maxCreatedColumnIdBeforeUpdate = !originalCreatedColumns.isEmpty() ? originalCreatedColumns.stream().mapToInt(Integer::parseInt).max().getAsInt() : MAX_VALUE;
        // Build list of actions from modified one to the head
        final List<AppendStep> actionsSteps = getStepsWithShiftedColumnIds(steps, stepToModifyId, deletedColumns, maxCreatedColumnIdBeforeUpdate, columnsDiffNumber);
        actionsSteps.add(0, newStep);
        // Rebuild history from modified step
        final Step stepToModify = getStep(stepToModifyId);
        replaceHistory(preparation, stepToModify.getParent(), actionsSteps);
        LOGGER.debug("Modified head of preparation #{}: head is now {}", preparation.getHeadId());
    } finally {
        unlockPreparation(preparationId);
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) PREPARATION(org.talend.dataprep.api.folder.FolderContentType.PREPARATION) ActionFactory(org.talend.dataprep.transformation.actions.common.ActionFactory) MAX_VALUE(java.lang.Integer.MAX_VALUE) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) PreparationRepository(org.talend.dataprep.preparation.store.PreparationRepository) LockedResourceRepository(org.talend.dataprep.lock.store.LockedResourceRepository) BeanConversionService(org.talend.dataprep.conversions.BeanConversionService) DataprepBundle.message(org.talend.dataprep.i18n.DataprepBundle.message) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) ConstraintViolation(javax.validation.ConstraintViolation) Collectors.toSet(java.util.stream.Collectors.toSet) Order(org.talend.dataprep.util.SortAndOrderHelper.Order) Collections.emptyList(java.util.Collections.emptyList) Predicate(java.util.function.Predicate) Validator(javax.validation.Validator) PreparationErrorCodes(org.talend.dataprep.exception.error.PreparationErrorCodes) Collectors(java.util.stream.Collectors) Stream(java.util.stream.Stream) SortAndOrderHelper.getPreparationComparator(org.talend.dataprep.util.SortAndOrderHelper.getPreparationComparator) Pattern(java.util.regex.Pattern) ActionDefinition(org.talend.dataprep.api.action.ActionDefinition) Security(org.talend.dataprep.security.Security) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) IntStream(java.util.stream.IntStream) ImplicitParameters(org.talend.dataprep.transformation.actions.common.ImplicitParameters) java.util(java.util) TDPException(org.talend.dataprep.exception.TDPException) TqlBuilder(org.talend.tql.api.TqlBuilder) JsonErrorCodeDescription(org.talend.dataprep.exception.json.JsonErrorCodeDescription) org.talend.dataprep.api.preparation(org.talend.dataprep.api.preparation) Expression(org.talend.tql.model.Expression) Function(java.util.function.Function) FolderEntry(org.talend.dataprep.api.folder.FolderEntry) ExceptionContext.build(org.talend.daikon.exception.ExceptionContext.build) ExceptionContext(org.talend.daikon.exception.ExceptionContext) Folder(org.talend.dataprep.api.folder.Folder) Service(org.springframework.stereotype.Service) VersionService(org.talend.dataprep.api.service.info.VersionService) FolderRepository(org.talend.dataprep.folder.store.FolderRepository) Logger(org.slf4j.Logger) ActionRegistry(org.talend.dataprep.transformation.pipeline.ActionRegistry) DecimalFormat(java.text.DecimalFormat) Sort(org.talend.dataprep.util.SortAndOrderHelper.Sort) PreparationSearchCriterion.filterPreparation(org.talend.dataprep.preparation.service.PreparationSearchCriterion.filterPreparation) Collectors.toList(java.util.stream.Collectors.toList) ActionMetadataValidation(org.talend.dataprep.transformation.api.action.validation.ActionMetadataValidation) Lookup(org.talend.dataprep.transformation.actions.datablending.Lookup) DataSetGetMetadata(org.talend.dataprep.command.dataset.DataSetGetMetadata) PATH_SEPARATOR(org.talend.dataprep.folder.store.FoldersRepositoriesConstants.PATH_SEPARATOR) PreparationSearchCriterion.filterPreparation(org.talend.dataprep.preparation.service.PreparationSearchCriterion.filterPreparation)

Aggregations

MAX_VALUE (java.lang.Integer.MAX_VALUE)1 DecimalFormat (java.text.DecimalFormat)1 java.util (java.util)1 Collections.emptyList (java.util.Collections.emptyList)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 ConstraintViolation (javax.validation.ConstraintViolation)1 Validator (javax.validation.Validator)1 StringUtils (org.apache.commons.lang.StringUtils)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Service (org.springframework.stereotype.Service)1 ExceptionContext (org.talend.daikon.exception.ExceptionContext)1