Search in sources :

Example 1 with Expression

use of org.talend.tql.model.Expression in project data-prep by Talend.

the class PreparationService method listAll.

public Stream<UserPreparation> listAll(PreparationSearchCriterion searchCriterion, Sort sort, Order order) {
    LOGGER.debug("Get list of preparations (with details).");
    Stream<Preparation> preparationStream;
    if (searchCriterion.getName() == null && searchCriterion.getDataSetId() == null) {
        preparationStream = preparationRepository.list(Preparation.class);
    } else {
        Expression filter = null;
        if (searchCriterion.getName() != null) {
            filter = getNameFilter(searchCriterion.getName(), searchCriterion.isNameExactMatch());
        }
        if (searchCriterion.getDataSetId() != null) {
            Expression dataSetFilter = eq("dataSetId", searchCriterion.getDataSetId());
            filter = filter == null ? dataSetFilter : and(filter, dataSetFilter);
        }
        preparationStream = preparationRepository.list(Preparation.class, filter);
    }
    // filter on path
    if (searchCriterion.getFolderPath() != null || searchCriterion.getFolderId() != null) {
        Map<String, Folder> preparationsFolder = folderRepository.getPreparationsFolderPaths();
        if (searchCriterion.getFolderPath() != null) {
            preparationStream = preparationStream.filter(p -> preparationsFolder.get(p.getId()).getPath().equals(searchCriterion.getFolderPath()));
        }
        if (searchCriterion.getFolderId() != null) {
            preparationStream = preparationStream.filter(p -> preparationsFolder.get(p.getId()).getId().equals(searchCriterion.getFolderId()));
        }
    }
    return // Needed to order on
    preparationStream.map(p -> beanConversionService.convert(p, UserPreparation.class)).sorted(getPreparationComparator(sort, order, p -> getDatasetMetadata(p.getDataSetId())));
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) PREPARATION(org.talend.dataprep.api.folder.FolderContentType.PREPARATION) ActionFactory(org.talend.dataprep.transformation.actions.common.ActionFactory) MAX_VALUE(java.lang.Integer.MAX_VALUE) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) PreparationRepository(org.talend.dataprep.preparation.store.PreparationRepository) LockedResourceRepository(org.talend.dataprep.lock.store.LockedResourceRepository) BeanConversionService(org.talend.dataprep.conversions.BeanConversionService) DataprepBundle.message(org.talend.dataprep.i18n.DataprepBundle.message) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) ConstraintViolation(javax.validation.ConstraintViolation) Collectors.toSet(java.util.stream.Collectors.toSet) Order(org.talend.dataprep.util.SortAndOrderHelper.Order) Collections.emptyList(java.util.Collections.emptyList) Predicate(java.util.function.Predicate) Validator(javax.validation.Validator) PreparationErrorCodes(org.talend.dataprep.exception.error.PreparationErrorCodes) Collectors(java.util.stream.Collectors) Stream(java.util.stream.Stream) SortAndOrderHelper.getPreparationComparator(org.talend.dataprep.util.SortAndOrderHelper.getPreparationComparator) 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) ImplicitParameters(org.talend.dataprep.transformation.actions.common.ImplicitParameters) java.util(java.util) TDPException(org.talend.dataprep.exception.TDPException) TqlBuilder(org.talend.tql.api.TqlBuilder) JsonErrorCodeDescription(org.talend.dataprep.exception.json.JsonErrorCodeDescription) org.talend.dataprep.api.preparation(org.talend.dataprep.api.preparation) Expression(org.talend.tql.model.Expression) Function(java.util.function.Function) 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) VersionService(org.talend.dataprep.api.service.info.VersionService) FolderRepository(org.talend.dataprep.folder.store.FolderRepository) Logger(org.slf4j.Logger) ActionRegistry(org.talend.dataprep.transformation.pipeline.ActionRegistry) DecimalFormat(java.text.DecimalFormat) Sort(org.talend.dataprep.util.SortAndOrderHelper.Sort) PreparationSearchCriterion.filterPreparation(org.talend.dataprep.preparation.service.PreparationSearchCriterion.filterPreparation) Collectors.toList(java.util.stream.Collectors.toList) ActionMetadataValidation(org.talend.dataprep.transformation.api.action.validation.ActionMetadataValidation) Lookup(org.talend.dataprep.transformation.actions.datablending.Lookup) DataSetGetMetadata(org.talend.dataprep.command.dataset.DataSetGetMetadata) PATH_SEPARATOR(org.talend.dataprep.folder.store.FoldersRepositoriesConstants.PATH_SEPARATOR) Expression(org.talend.tql.model.Expression) PreparationSearchCriterion.filterPreparation(org.talend.dataprep.preparation.service.PreparationSearchCriterion.filterPreparation) Folder(org.talend.dataprep.api.folder.Folder)

Aggregations

MAX_VALUE (java.lang.Integer.MAX_VALUE)1 DecimalFormat (java.text.DecimalFormat)1 java.util (java.util)1 Collections.emptyList (java.util.Collections.emptyList)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 ConstraintViolation (javax.validation.ConstraintViolation)1 Validator (javax.validation.Validator)1 StringUtils (org.apache.commons.lang.StringUtils)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Service (org.springframework.stereotype.Service)1 ExceptionContext (org.talend.daikon.exception.ExceptionContext)1