Search in sources :

Example 1 with SharedInjection

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));
}
Also used : LocaleContextHolder(org.springframework.context.i18n.LocaleContextHolder) PREPARATION(org.talend.dataprep.api.folder.FolderContentType.PREPARATION) TqlBuilder.match(org.talend.tql.api.TqlBuilder.match) ActionFactory(org.talend.dataprep.transformation.actions.common.ActionFactory) Date(java.util.Date) MAX_VALUE(java.lang.Integer.MAX_VALUE) LoggerFactory(org.slf4j.LoggerFactory) TqlBuilder.and(org.talend.tql.api.TqlBuilder.and) Autowired(org.springframework.beans.factory.annotation.Autowired) PreparationRepository(org.talend.dataprep.preparation.store.PreparationRepository) StringUtils(org.apache.commons.lang3.StringUtils) StepRowMetadata(org.talend.dataprep.api.preparation.StepRowMetadata) LockedResourceRepository(org.talend.dataprep.lock.store.LockedResourceRepository) BeanConversionService(org.talend.dataprep.conversions.BeanConversionService) AppendStep(org.talend.dataprep.api.preparation.AppendStep) Collectors.toMap(java.util.stream.Collectors.toMap) Locale(java.util.Locale) Map(java.util.Map) DataprepBundle.message(org.talend.dataprep.i18n.DataprepBundle.message) PREPARATION_NOT_EMPTY(org.talend.dataprep.exception.error.PreparationErrorCodes.PREPARATION_NOT_EMPTY) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions) Collectors.toSet(java.util.stream.Collectors.toSet) StepDiff(org.talend.dataprep.api.preparation.StepDiff) PREPARATION_ROOT_STEP_CANNOT_BE_DELETED(org.talend.dataprep.exception.error.PreparationErrorCodes.PREPARATION_ROOT_STEP_CANNOT_BE_DELETED) Order(org.talend.dataprep.util.SortAndOrderHelper.Order) Collections.emptyList(java.util.Collections.emptyList) Predicate(java.util.function.Predicate) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) Set(java.util.Set) PreparationErrorCodes(org.talend.dataprep.exception.error.PreparationErrorCodes) PREPARATION_STEP_CANNOT_BE_REORDERED(org.talend.dataprep.exception.error.PreparationErrorCodes.PREPARATION_STEP_CANNOT_BE_REORDERED) UUID(java.util.UUID) PREPARATION_STEP_DOES_NOT_EXIST(org.talend.dataprep.exception.error.PreparationErrorCodes.PREPARATION_STEP_DOES_NOT_EXIST) Objects(java.util.Objects) List(java.util.List) BaseDataprepAuditService(org.talend.dataprep.audit.BaseDataprepAuditService) Stream(java.util.stream.Stream) SortAndOrderHelper.getPreparationComparator(org.talend.dataprep.util.SortAndOrderHelper.getPreparationComparator) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) ActionDefinition(org.talend.dataprep.api.action.ActionDefinition) Security(org.talend.dataprep.security.Security) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) IntStream(java.util.stream.IntStream) TqlBuilder.isEmpty(org.talend.tql.api.TqlBuilder.isEmpty) ImplicitParameters(org.talend.dataprep.transformation.actions.common.ImplicitParameters) TDPException(org.talend.dataprep.exception.TDPException) CREATE_NEW_COLUMN(org.talend.dataprep.transformation.actions.common.ActionsUtils.CREATE_NEW_COLUMN) JsonErrorCodeDescription(org.talend.dataprep.exception.json.JsonErrorCodeDescription) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Deque(java.util.Deque) Expression(org.talend.tql.model.Expression) Function(java.util.function.Function) PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation) DatasetClient(org.talend.dataprep.dataset.adapter.DatasetClient) ArrayList(java.util.ArrayList) PREPARATION_NAME_ALREADY_USED(org.talend.dataprep.exception.error.PreparationErrorCodes.PREPARATION_NAME_ALREADY_USED) HashSet(java.util.HashSet) FolderEntry(org.talend.dataprep.api.folder.FolderEntry) ExceptionContext.build(org.talend.daikon.exception.ExceptionContext.build) ExceptionContext(org.talend.daikon.exception.ExceptionContext) Folder(org.talend.dataprep.api.folder.Folder) Service(org.springframework.stereotype.Service) PREPARATION_DOES_NOT_EXIST(org.talend.dataprep.exception.error.PreparationErrorCodes.PREPARATION_DOES_NOT_EXIST) VersionService(org.talend.dataprep.api.service.info.VersionService) Action(org.talend.dataprep.api.preparation.Action) OwnerInjection(org.talend.dataprep.conversions.inject.OwnerInjection) Preparation(org.talend.dataprep.api.preparation.Preparation) PreparationDetailsDTO(org.talend.dataprep.api.preparation.PreparationDetailsDTO) FolderRepository(org.talend.dataprep.folder.store.FolderRepository) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) ActionRegistry(org.talend.dataprep.transformation.pipeline.ActionRegistry) DecimalFormat(java.text.DecimalFormat) Sort(org.talend.dataprep.util.SortAndOrderHelper.Sort) Step(org.talend.dataprep.api.preparation.Step) PreparationSearchCriterion.filterPreparation(org.talend.dataprep.preparation.service.PreparationSearchCriterion.filterPreparation) ActionForm(org.talend.dataprep.api.action.ActionForm) PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) TqlBuilder.eq(org.talend.tql.api.TqlBuilder.eq) Collectors.toList(java.util.stream.Collectors.toList) PreparationUtils(org.talend.dataprep.api.preparation.PreparationUtils) SharedInjection(org.talend.dataprep.preparation.configuration.SharedInjection) ActionMetadataValidation(org.talend.dataprep.transformation.api.action.validation.ActionMetadataValidation) Lookup(org.talend.dataprep.transformation.actions.datablending.Lookup) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) PATH_SEPARATOR(org.talend.dataprep.folder.store.FoldersRepositoriesConstants.PATH_SEPARATOR) ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) Folder(org.talend.dataprep.api.folder.Folder) Expression(org.talend.tql.model.Expression) FolderEntry(org.talend.dataprep.api.folder.FolderEntry) PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation) HashSet(java.util.HashSet)

Aggregations

MAX_VALUE (java.lang.Integer.MAX_VALUE)1 DecimalFormat (java.text.DecimalFormat)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Collections.emptyList (java.util.Collections.emptyList)1 Date (java.util.Date)1 Deque (java.util.Deque)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 UUID (java.util.UUID)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1