use of org.talend.dataprep.command.preparation.PreparationGetActions in project data-prep by Talend.
the class PreparationAPI method updatePreparationAction.
// @formatter:off
@RequestMapping(value = "/api/preparations/{preparationId}/actions/{stepId}", method = PUT, produces = APPLICATION_JSON_VALUE)
@ApiOperation(value = "Updates an action in the preparation.", notes = "Does not return any value, client may expect successful operation based on HTTP status code.")
@Timed
public void updatePreparationAction(@ApiParam(name = "preparationId", value = "Preparation id.") @PathVariable(value = "preparationId") final String preparationId, @ApiParam(name = "stepId", value = "Step id in the preparation.") @PathVariable(value = "stepId") final String stepId, @ApiParam("New content for the action.") @RequestBody final AppendStep step) {
if (LOG.isDebugEnabled()) {
LOG.debug("Updating preparation action at step #{} (pool: {} )...", stepId, getConnectionStats());
}
// get the preparation
Preparation preparation = internalGetPreparation(preparationId);
// get the preparation actions for up to the updated action
final int stepIndex = preparation.getSteps().stream().map(Step::getId).collect(toList()).indexOf(stepId);
final String parentStepId = preparation.getSteps().get(stepIndex - 1).id();
final PreparationGetActions getActionsCommand = getCommand(PreparationGetActions.class, preparationId, parentStepId);
// get the diff
final DiffMetadata diffCommand = getCommand(DiffMetadata.class, preparation.getDataSetId(), preparationId, step.getActions(), getActionsCommand);
// get the update action command and execute it
final HystrixCommand<Void> command = getCommand(PreparationUpdateAction.class, preparationId, stepId, step, diffCommand);
command.execute();
if (LOG.isDebugEnabled()) {
LOG.debug("Updated preparation action at step #{} (pool: {} )...", stepId, getConnectionStats());
}
}
use of org.talend.dataprep.command.preparation.PreparationGetActions in project data-prep by Talend.
the class BaseExportStrategy method getActions.
/**
* Returns the actions for the preparation with <code>preparationId</code> between <code>startStepId</code> and
* <code>endStepId</code>.
*
* @param preparationId The preparation id, if <code>null</code> or blank, returns <code>{actions: []}</code>
* @param startStepId A step id that must exist in given preparation id.
* @param endStepId A step id that must exist in given preparation id.
* @return The actions that can be parsed by ActionParser.
* @see org.talend.dataprep.transformation.api.action.ActionParser
*/
protected String getActions(String preparationId, String startStepId, String endStepId) {
if (Step.ROOT_STEP.id().equals(startStepId)) {
return getActions(preparationId, endStepId);
}
String actions;
if (StringUtils.isBlank(preparationId)) {
actions = "{\"actions\": []}";
} else {
try {
final PreparationGetActions startStepActions = applicationContext.getBean(PreparationGetActions.class, preparationId, startStepId);
final PreparationGetActions endStepActions = applicationContext.getBean(PreparationGetActions.class, preparationId, endStepId);
final StringWriter actionsAsString = new StringWriter();
final Action[] startActions = mapper.readValue(startStepActions.execute(), Action[].class);
final Action[] endActions = mapper.readValue(endStepActions.execute(), Action[].class);
if (endActions.length > startActions.length) {
final Action[] filteredActions = (Action[]) ArrayUtils.subarray(endActions, startActions.length, endActions.length);
LOGGER.debug("Reduced actions list from {} to {} action(s)", endActions.length, filteredActions.length);
mapper.writeValue(actionsAsString, filteredActions);
} else {
LOGGER.debug("Unable to reduce list of actions (has {})", endActions.length);
mapper.writeValue(actionsAsString, endActions);
}
return "{\"actions\": " + actionsAsString + '}';
} catch (IOException e) {
final ExceptionContext context = ExceptionContext.build().put("id", preparationId).put("version", endStepId);
throw new TDPException(UNABLE_TO_READ_PREPARATION, e, context);
}
}
return actions;
}
use of org.talend.dataprep.command.preparation.PreparationGetActions in project data-prep by Talend.
the class PreparationExportStrategyTest method setUp.
@Before
public void setUp() throws Exception {
// Given
mapper.registerModule(new Jdk8Module());
strategy.setMapper(new ObjectMapper());
when(formatRegistrationService.getByName(eq("JSON"))).thenReturn(new JsonFormat());
final DataSetGetMetadata dataSetGetMetadata = mock(DataSetGetMetadata.class);
when(applicationContext.getBean(eq(DataSetGetMetadata.class), anyVararg())).thenReturn(dataSetGetMetadata);
DataSetGet dataSetGet = mock(DataSetGet.class);
final StringWriter dataSetAsString = new StringWriter();
DataSet dataSet = new DataSet();
final DataSetMetadata dataSetMetadata = new DataSetMetadata("ds-1234", "", "", 0L, 0L, new RowMetadata(), "");
final DataSetContent content = new DataSetContent();
dataSetMetadata.setContent(content);
dataSet.setMetadata(dataSetMetadata);
dataSet.setRecords(Stream.empty());
mapper.writerFor(DataSet.class).writeValue(dataSetAsString, dataSet);
when(dataSetGet.execute()).thenReturn(new ByteArrayInputStream(dataSetAsString.toString().getBytes()));
when(applicationContext.getBean(eq(DataSetGet.class), anyVararg())).thenReturn(dataSetGet);
final PreparationGetActions preparationGetActions = mock(PreparationGetActions.class);
when(preparationGetActions.execute()).thenReturn(new ByteArrayInputStream("{}".getBytes()));
when(applicationContext.getBean(eq(PreparationGetActions.class), eq("prep-1234"), anyString())).thenReturn(preparationGetActions);
final TransformationCacheKey cacheKey = mock(TransformationCacheKey.class);
when(cacheKey.getKey()).thenReturn("cache-1234");
when(cacheKeyGenerator.generateContentKey(anyString(), anyString(), anyString(), anyString(), any(), any(), anyString())).thenReturn(cacheKey);
final ExecutableTransformer executableTransformer = mock(ExecutableTransformer.class);
reset(transformer);
when(transformer.buildExecutable(any(), any())).thenReturn(executableTransformer);
when(factory.get(any())).thenReturn(transformer);
when(contentCache.put(any(), any())).thenReturn(new NullOutputStream());
}
Aggregations