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);
}
}
Aggregations