use of org.talend.dataprep.api.preparation.PreparationDTO 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;
}
use of org.talend.dataprep.api.preparation.PreparationDTO in project data-prep by Talend.
the class PreparationService method listAll.
public Stream<PreparationDTO> listAll(PreparationSearchCriterion searchCriterion, Sort sort, Order order) {
LOGGER.debug("Get list of preparations (with details).");
Stream<PersistentPreparation> preparationStream;
Expression filter = null;
Predicate<PersistentPreparation> deprecatedFolderIdFilter = null;
if (searchCriterion.getName() != null) {
filter = getNameFilter(searchCriterion.getName(), searchCriterion.isNameExactMatch());
}
if (searchCriterion.getDataSetId() != null) {
Expression dataSetFilter = eq(DATASET_ID, searchCriterion.getDataSetId());
filter = filter == null ? dataSetFilter : and(filter, dataSetFilter);
}
if (searchCriterion.getFolderId() != null) {
if (preparationRepository.exist(PersistentPreparation.class, isEmpty(FOLDER_ID))) {
// filter on folder id (DEPRECATED VERSION - only applies if migration isn't completed yet)
try (Stream<FolderEntry> folders = folderRepository.entries(searchCriterion.getFolderId(), PREPARATION)) {
final Set<String> entries = folders.map(//
FolderEntry::getContentId).collect(toSet());
deprecatedFolderIdFilter = p -> entries.contains(p.id());
}
} else {
// Once all preparations all have the folder id,
Expression folderIdFilter = eq(FOLDER_ID, searchCriterion.getFolderId());
filter = filter == null ? folderIdFilter : and(filter, folderIdFilter);
}
}
// Handles filtering (prefer database filters)
if (filter != null) {
preparationStream = preparationRepository.list(PersistentPreparation.class, filter);
} else {
preparationStream = preparationRepository.list(PersistentPreparation.class);
}
// migration for preparation after the change from dataset ID to dataset name
// see TDP-6195 and TDP-5696
preparationStream = preparationStream.map(dataSetNameInjection::injectDatasetNameBasedOnId);
if (deprecatedFolderIdFilter != null) {
// filter on folder id (DEPRECATED VERSION - only applies if migration isn't completed yet)
preparationStream = //
preparationStream.filter(//
deprecatedFolderIdFilter).peek(p -> p.setFolderId(searchCriterion.getFolderId()));
}
// filter on folder path
if (searchCriterion.getFolderPath() != null) {
final Optional<Folder> folder = folderRepository.getFolder(searchCriterion.getFolderPath());
final Set<String> folderEntries = new HashSet<>();
folder.ifPresent(f -> {
try (Stream<String> preparationIds = //
folderRepository.entries(f.getId(), //
PREPARATION).map(FolderEntry::getContentId)) {
folderEntries.addAll(//
preparationIds.collect(toSet()));
}
});
preparationStream = preparationStream.filter(p -> folderEntries.contains(p.id()));
}
return preparationStream.map(preparation -> {
if (StringUtils.isEmpty(preparation.getName())) {
preparation.setName((preparation.getDataSetName() != null ? preparation.getDataSetName() + " " : "") + message("preparation.create.suffix"));
preparationRepository.add(preparation);
}
return preparation;
}).map(p -> beanConversionService.convert(p, PreparationDTO.class, ownerInjection.injectIntoPreparation(), //
sharedInjection)).sorted(getPreparationComparator(sort, order));
}
use of org.talend.dataprep.api.preparation.PreparationDTO in project data-prep by Talend.
the class PreparationControllerTest method update.
@Test
public void update() throws Exception {
assertThat(repository.list(Preparation.class).count(), is(0L));
final String preparationId = clientTest.createPreparation(createTestPreparation("test_name", "1234")).getId();
final Preparation createdPreparation = repository.list(Preparation.class).iterator().next();
assertThat(createdPreparation.getId(), is(preparationId));
final long oldModificationDate = createdPreparation.getLastModificationDate();
// Test preparation details update
PreparationDTO forUpdate = new PreparationDTO();
forUpdate.setName("test_name_updated");
forUpdate.setDataSetId("1234");
final String updatedId = given().contentType(//
ContentType.JSON).body(//
forUpdate).when().put("/preparations/{id}", //
preparationId).asString();
// Preparation id should not change (name is not part of preparation id).
assertThat(updatedId, is(preparationId));
final Collection<Preparation> preparations = repository.list(Preparation.class).collect(Collectors.toList());
assertThat(preparations.size(), is(1));
final Preparation preparation = preparations.iterator().next();
assertThat(preparation.getName(), is("test_name_updated"));
assertThat(preparation.getLastModificationDate(), is(greaterThan(oldModificationDate)));
assertThat(preparation.getAppVersion(), is(versionService.version().getVersionId()));
}
use of org.talend.dataprep.api.preparation.PreparationDTO in project data-prep by Talend.
the class PreparationControllerTest method updateWithSpecialArguments.
@Test
public void updateWithSpecialArguments() throws Exception {
// given
final Preparation createdPreparation = new Preparation("#123", versionService.version().getVersionId());
createdPreparation.setDataSetId("1234");
createdPreparation.setName("test_name");
createdPreparation.setRowMetadata(new RowMetadata());
final String preparationId = clientTest.createPreparation(createdPreparation).getId();
// when
final PreparationDTO forUpdate = new PreparationDTO();
forUpdate.setName("éàçè");
forUpdate.setDataSetId("1234");
final String updatedId = given().contentType(//
ContentType.JSON.withCharset(UTF_8)).body(//
forUpdate).when().put("/preparations/{id}", preparationId).asString();
// then
// Preparation id should not change (new name)
assertThat(updatedId, is(preparationId));
final Collection<Preparation> preparations = repository.list(Preparation.class).collect(Collectors.toList());
assertThat(preparations.size(), is(1));
final Preparation preparation = preparations.iterator().next();
assertThat(preparation.id(), is(updatedId));
assertThat(preparation.getName(), is("éàçè"));
}
use of org.talend.dataprep.api.preparation.PreparationDTO in project data-prep by Talend.
the class PreparationServiceTest method updateHeadAndCheckResult.
private void updateHeadAndCheckResult(PreparationDTO prep, List<String> originalStepIds, Integer indexOfStep) {
preparationService.setPreparationHead(prep.getId(), originalStepIds.get(indexOfStep));
PreparationDTO updatedPrep = preparationService.getPreparation(prep.getId());
// we check that headId is the correct one and there is only one step on the list
assertNotNull(updatedPrep);
assertEquals(originalStepIds.get(indexOfStep), updatedPrep.getHeadId());
assertEquals(indexOfStep + 1, updatedPrep.getSteps().size());
assertEquals(originalStepIds.get(indexOfStep), updatedPrep.getSteps().get(indexOfStep));
}
Aggregations