use of org.talend.dataprep.preparation.configuration.SharedInjection 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));
}
Aggregations