use of org.talend.dataprep.api.preparation.Preparation in project data-prep by Talend.
the class PreparationTest method initialStepWithAppend.
@Test
public void initialStepWithAppend() {
final String version = versionService.version().getVersionId();
final List<Action> actions = getSimpleAction("uppercase", "column_name", "lastname");
final PreparationActions newContent = PreparationActions.ROOT_ACTIONS.append(actions);
repository.add(newContent);
final Step s = new Step(Step.ROOT_STEP.id(), newContent.id(), version);
repository.add(s);
final Preparation preparation = new Preparation("#5438743", "1234", s.id(), version);
preparation.setCreationDate(0L);
repository.add(preparation);
assertThat(preparation.id(), Is.is("#5438743"));
}
use of org.talend.dataprep.api.preparation.Preparation in project data-prep by Talend.
the class DataSetAPI method listSummary.
@RequestMapping(value = "/api/datasets/summary", method = GET, produces = APPLICATION_JSON_VALUE)
@ApiOperation(value = "List data sets summary.", produces = APPLICATION_JSON_VALUE, notes = "Returns a list of data sets summary the user can use.")
@Timed
public Callable<Stream<EnrichedDataSetMetadata>> listSummary(@ApiParam(value = "Sort key (by name or date), defaults to 'date'.") @RequestParam(defaultValue = "creationDate") Sort sort, @ApiParam(value = "Order for sort key (desc or asc), defaults to 'desc'.") @RequestParam(defaultValue = "desc") Order order, @ApiParam(value = "Filter on name containing the specified name") @RequestParam(defaultValue = "") String name, @ApiParam(value = "Filter on certified data sets") @RequestParam(defaultValue = "false") boolean certified, @ApiParam(value = "Filter on favorite data sets") @RequestParam(defaultValue = "false") boolean favorite, @ApiParam(value = "Filter on recent data sets") @RequestParam(defaultValue = "false") boolean limit) {
if (LOG.isDebugEnabled()) {
LOG.debug("Listing datasets summary (pool: {})...", getConnectionStats());
}
return () -> {
GenericCommand<InputStream> listDataSets = getCommand(DataSetList.class, sort, order, name, certified, favorite, limit);
return //
Flux.from(CommandHelper.toPublisher(UserDataSetMetadata.class, mapper, listDataSets)).map(m -> {
LOG.debug("found dataset {} in the summary list" + m.getName());
// Add the related preparations list to the given dataset metadata.
final PreparationSearchByDataSetId getPreparations = getCommand(PreparationSearchByDataSetId.class, m.getId());
return //
Flux.from(CommandHelper.toPublisher(Preparation.class, mapper, getPreparations)).collectList().map(preparations -> {
final List<Preparation> list = //
preparations.stream().filter(//
p -> p.getSteps() != null).collect(Collectors.toList());
return new EnrichedDataSetMetadata(m, list);
}).block();
}).toStream(1);
};
}
use of org.talend.dataprep.api.preparation.Preparation in project data-prep by Talend.
the class SearchAPITest method shouldNotReturnNonMatchingPreparationsWhenPerformingInventory.
@Test
public void shouldNotReturnNonMatchingPreparationsWhenPerformingInventory() throws IOException {
// given
testClient.createPreparationFromFile("t-shirt_100.csv", "nonMatchingPreparation", home.getId());
// when
final Response response = //
given().queryParam("name", //
"Inventory").when().expect().statusCode(200).log().ifError().get("/api/search");
// then
assertEquals(200, response.getStatusCode());
JsonNode rootNode = mapper.readTree(response.asInputStream());
JsonNode preparations = rootNode.get("preparations");
List<Preparation> preparationList = mapper.readValue(preparations.toString(), new TypeReference<List<Preparation>>() {
});
assertThat(preparationList.size(), is(0));
}
use of org.talend.dataprep.api.preparation.Preparation in project data-prep by Talend.
the class PreparationCleanerTest method shouldNotRemovePreparationActions_sharedByMultiplePreparation.
@Test
public void shouldNotRemovePreparationActions_sharedByMultiplePreparation() throws Exception {
// given
final String version = "1.2.3";
final PreparationActions content = new PreparationActions();
List<Action> actions = new ArrayList<>();
content.append(actions);
content.setAppVersion(version);
when(repository.list(PreparationActions.class)).thenReturn(Stream.of(content));
when(repository.get(content.id(), PreparationActions.class)).thenReturn(content);
// 2 preparations, with each, one step that shares the same action
final Step stepFirstPreparation = new Step(Step.ROOT_STEP.getId(), content.getId(), version);
final Step stepSecondPreparation = new Step(Step.ROOT_STEP.getId(), content.getId(), version);
// add the steps to the repository
when(repository.exist(eq(PersistentStep.class), eq(TqlBuilder.eq("contentId", content.id())))).thenReturn(true);
when(repository.list(Step.class)).thenReturn(Stream.of(stepFirstPreparation, stepSecondPreparation));
when(repository.list(eq(PersistentStep.class))).thenReturn(Stream.of(stepFirstPreparation, stepSecondPreparation).map(s -> {
final PersistentStep persistentStep = new PersistentStep();
persistentStep.setId(s.id());
persistentStep.setContent(s.getContent());
return persistentStep;
}));
Preparation firstPreparation = new Preparation("1", null, stepFirstPreparation.getId(), version);
firstPreparation.setSteps(Collections.singletonList(stepFirstPreparation));
Preparation secondPreparation = new Preparation("2", null, stepSecondPreparation.getId(), version);
secondPreparation.setSteps(Collections.singletonList(stepSecondPreparation));
// add the preparations to the repository
when(repository.list(Preparation.class)).thenReturn(Stream.of(firstPreparation, secondPreparation));
// when
cleaner.removeOrphanSteps();
// then
verify(repository, never()).remove(eq(content));
}
use of org.talend.dataprep.api.preparation.Preparation in project data-prep by Talend.
the class PreparationCleanerTest method shouldNotRemovePreparationActions_ownedByOnePreparation.
@Test
public void shouldNotRemovePreparationActions_ownedByOnePreparation() throws Exception {
// given
final String version = "1.2.3";
final PreparationActions content = new PreparationActions();
List<Action> actions = new ArrayList<>();
content.append(actions);
content.setAppVersion(version);
when(repository.list(PreparationActions.class)).thenReturn(Stream.of(content));
when(repository.get(content.id(), PreparationActions.class)).thenReturn(content);
// 2 preparations, with each, one step that shares the same action
final Step stepFirstPreparation = new Step(Step.ROOT_STEP.getId(), content.getId(), version);
final Step stepSecondPreparation = new Step(Step.ROOT_STEP.getId(), content.getId(), version);
// add the steps to the repository
when(repository.list(Step.class)).thenReturn(Stream.of(stepFirstPreparation, stepSecondPreparation));
when(repository.list(eq(PersistentStep.class))).thenReturn(Stream.of(stepFirstPreparation, stepSecondPreparation).map(s -> {
final PersistentStep persistentStep = new PersistentStep();
persistentStep.setId(s.id());
persistentStep.setContent(s.getContent());
return persistentStep;
}));
Preparation firstPreparation = new Preparation("1", null, stepFirstPreparation.getId(), version);
firstPreparation.setSteps(Collections.singletonList(stepFirstPreparation));
Preparation secondPreparation = new Preparation("2", null, stepSecondPreparation.getId(), version);
secondPreparation.setSteps(Collections.singletonList(stepSecondPreparation));
// add the preparations to the repository
when(repository.exist(eq(PersistentStep.class), any())).thenReturn(true);
// Remove first preparation
when(repository.list(Preparation.class)).thenReturn(Stream.of(secondPreparation));
// when
cleaner.removeOrphanSteps();
// then
// when the first preparation is removed, the shared action is not deleted
verify(repository, never()).remove(eq(content));
}
Aggregations