Search in sources :

Example 1 with PREPARATION

use of org.talend.dataprep.api.folder.FolderContentType.PREPARATION in project data-prep by Talend.

the class FolderService method list.

/**
 * Get folders. If parentId is supplied, it will be used as filter.
 *
 * @param parentId the parent folder id parameter
 * @return direct sub folders for the given id.
 */
// @formatter:off
@RequestMapping(value = "/folders", method = GET)
@ApiOperation(value = "List children folders of the parameter if null list root children.", notes = "List all child folders of the one as parameter")
@Timed
public Stream<Folder> list(@RequestParam(required = false) @ApiParam(value = "Parent id filter.") String parentId, @RequestParam(defaultValue = "lastModificationDate") @ApiParam(value = "Sort key (by name or date).") Sort sort, @RequestParam(defaultValue = "desc") @ApiParam(value = "Order for sort key (desc or asc).") Order order) {
    // @formatter:on
    Stream<Folder> children;
    if (parentId != null) {
        if (!folderRepository.exists(parentId)) {
            throw new TDPException(FOLDER_NOT_FOUND, build().put("id", parentId));
        }
        children = folderRepository.children(parentId);
    } else {
        // This will list all folders
        children = folderRepository.searchFolders("", false);
    }
    final AtomicInteger folderCount = new AtomicInteger();
    // update the number of preparations in each children
    children = children.peek(f -> {
        final long count = folderRepository.count(f.getId(), PREPARATION);
        f.setNbPreparations(count);
        folderCount.addAndGet(1);
    });
    LOGGER.info("Found {} children for parentId: {}", folderCount.get(), parentId);
    // sort the folders
    return children.sorted(getFolderComparator(sort, order));
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) TDPException(org.talend.dataprep.exception.TDPException) PREPARATION(org.talend.dataprep.api.folder.FolderContentType.PREPARATION) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ApiParam(io.swagger.annotations.ApiParam) FOLDER_NOT_FOUND(org.talend.dataprep.exception.error.FolderErrorCodes.FOLDER_NOT_FOUND) GET(org.springframework.web.bind.annotation.RequestMethod.GET) RequestBody(org.springframework.web.bind.annotation.RequestBody) ApiOperation(io.swagger.annotations.ApiOperation) ExceptionContext.build(org.talend.daikon.exception.ExceptionContext.build) ExceptionContext(org.talend.daikon.exception.ExceptionContext) Folder(org.talend.dataprep.api.folder.Folder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StreamSupport(java.util.stream.StreamSupport) Api(io.swagger.annotations.Api) FolderRepository(org.talend.dataprep.folder.store.FolderRepository) SortAndOrderHelper.getFolderComparator(org.talend.dataprep.util.SortAndOrderHelper.getFolderComparator) Logger(org.slf4j.Logger) DELETE(org.springframework.web.bind.annotation.RequestMethod.DELETE) Order(org.talend.dataprep.util.SortAndOrderHelper.Order) HttpResponseContext(org.talend.dataprep.http.HttpResponseContext) Sort(org.talend.dataprep.util.SortAndOrderHelper.Sort) FolderTreeNode(org.talend.dataprep.api.folder.FolderTreeNode) RestController(org.springframework.web.bind.annotation.RestController) HttpStatus(org.springframework.http.HttpStatus) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Stream(java.util.stream.Stream) Security(org.talend.dataprep.security.Security) Timed(org.talend.dataprep.metrics.Timed) FolderInfo(org.talend.dataprep.api.folder.FolderInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Folder(org.talend.dataprep.api.folder.Folder) Timed(org.talend.dataprep.metrics.Timed) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with PREPARATION

use of org.talend.dataprep.api.folder.FolderContentType.PREPARATION in project data-prep by Talend.

the class FolderService method search.

/**
 * Search for folders.
 *
 * @param name the folder name to search.
 * @param strict strict mode means the name is the full name.
 * @return the folders whose part of their name match the given path.
 */
@RequestMapping(value = "/folders/search", method = GET)
@ApiOperation(value = "Search Folders with parameter as part of the name")
@Timed
public Stream<Folder> search(@RequestParam(required = false, defaultValue = "") final String name, @RequestParam(required = false, defaultValue = "false") final Boolean strict, @RequestParam(required = false) final String path) {
    Stream<Folder> folders;
    if (path == null) {
        folders = folderRepository.searchFolders(name, strict);
    } else {
        folders = folderRepository.searchFolders(name, strict).filter(f -> f.getPath().equals(path));
    }
    AtomicInteger foldersFound = new AtomicInteger(0);
    folders = folders.peek(folder -> {
        folder.setNbPreparations(folderRepository.count(folder.getId(), PREPARATION));
        foldersFound.incrementAndGet();
    });
    LOGGER.info("Found {} folder(s) searching for {}", foldersFound, name);
    return folders;
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) TDPException(org.talend.dataprep.exception.TDPException) PREPARATION(org.talend.dataprep.api.folder.FolderContentType.PREPARATION) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ApiParam(io.swagger.annotations.ApiParam) FOLDER_NOT_FOUND(org.talend.dataprep.exception.error.FolderErrorCodes.FOLDER_NOT_FOUND) GET(org.springframework.web.bind.annotation.RequestMethod.GET) RequestBody(org.springframework.web.bind.annotation.RequestBody) ApiOperation(io.swagger.annotations.ApiOperation) ExceptionContext.build(org.talend.daikon.exception.ExceptionContext.build) ExceptionContext(org.talend.daikon.exception.ExceptionContext) Folder(org.talend.dataprep.api.folder.Folder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StreamSupport(java.util.stream.StreamSupport) Api(io.swagger.annotations.Api) FolderRepository(org.talend.dataprep.folder.store.FolderRepository) SortAndOrderHelper.getFolderComparator(org.talend.dataprep.util.SortAndOrderHelper.getFolderComparator) Logger(org.slf4j.Logger) DELETE(org.springframework.web.bind.annotation.RequestMethod.DELETE) Order(org.talend.dataprep.util.SortAndOrderHelper.Order) HttpResponseContext(org.talend.dataprep.http.HttpResponseContext) Sort(org.talend.dataprep.util.SortAndOrderHelper.Sort) FolderTreeNode(org.talend.dataprep.api.folder.FolderTreeNode) RestController(org.springframework.web.bind.annotation.RestController) HttpStatus(org.springframework.http.HttpStatus) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Stream(java.util.stream.Stream) Security(org.talend.dataprep.security.Security) Timed(org.talend.dataprep.metrics.Timed) FolderInfo(org.talend.dataprep.api.folder.FolderInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Folder(org.talend.dataprep.api.folder.Folder) Timed(org.talend.dataprep.metrics.Timed) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with PREPARATION

use of org.talend.dataprep.api.folder.FolderContentType.PREPARATION in project data-prep by Talend.

the class PreparationService method updateAction.

/**
 * Update a step in a preparation <b>Strategy</b><br/>
 * The goal here is to rewrite the preparation history from 'the step to modify' (STM) to the head, with STM
 * containing the new action.<br/>
 * <ul>
 * <li>1. Extract the actions from STM (excluded) to the head</li>
 * <li>2. Insert the new actions before the other extracted actions. The actions list contains all the actions from
 * the <b>NEW</b> STM to the head</li>
 * <li>3. Set preparation head to STM's parent, so STM will be excluded</li>
 * <li>4. Append each action (one step is created by action) after the new preparation head</li>
 * </ul>
 */
public void updateAction(final String preparationId, final String stepToModifyId, final AppendStep newStep) {
    checkActionStepConsistency(newStep);
    LOGGER.debug("Modifying actions in preparation #{}", preparationId);
    final Preparation preparation = lockPreparation(preparationId);
    try {
        LOGGER.debug("Current head for preparation #{}: {}", preparationId, preparation.getHeadId());
        // Get steps from "step to modify" to the head
        // throws an exception if stepId is not in
        final List<String> steps = extractSteps(preparation, stepToModifyId);
        // the preparation
        LOGGER.debug("Rewriting history for {} steps.", steps.size());
        // Extract created columns ids diff info
        final Step stm = getStep(stepToModifyId);
        final List<String> originalCreatedColumns = stm.getDiff().getCreatedColumns();
        final List<String> updatedCreatedColumns = newStep.getDiff().getCreatedColumns();
        final List<String> deletedColumns = // columns that the step was creating but
        originalCreatedColumns.stream().filter(id -> !updatedCreatedColumns.contains(id)).collect(toList());
        final int columnsDiffNumber = updatedCreatedColumns.size() - originalCreatedColumns.size();
        final int maxCreatedColumnIdBeforeUpdate = !originalCreatedColumns.isEmpty() ? originalCreatedColumns.stream().mapToInt(Integer::parseInt).max().getAsInt() : MAX_VALUE;
        // Build list of actions from modified one to the head
        final List<AppendStep> actionsSteps = getStepsWithShiftedColumnIds(steps, stepToModifyId, deletedColumns, maxCreatedColumnIdBeforeUpdate, columnsDiffNumber);
        actionsSteps.add(0, newStep);
        // Rebuild history from modified step
        final Step stepToModify = getStep(stepToModifyId);
        replaceHistory(preparation, stepToModify.getParent(), actionsSteps);
        LOGGER.debug("Modified head of preparation #{}: head is now {}", preparation.getHeadId());
    } finally {
        unlockPreparation(preparationId);
    }
}
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) PreparationSearchCriterion.filterPreparation(org.talend.dataprep.preparation.service.PreparationSearchCriterion.filterPreparation)

Example 4 with PREPARATION

use of org.talend.dataprep.api.folder.FolderContentType.PREPARATION 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

Collectors.toList (java.util.stream.Collectors.toList)4 Stream (java.util.stream.Stream)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 ExceptionContext (org.talend.daikon.exception.ExceptionContext)4 ExceptionContext.build (org.talend.daikon.exception.ExceptionContext.build)4 Folder (org.talend.dataprep.api.folder.Folder)4 PREPARATION (org.talend.dataprep.api.folder.FolderContentType.PREPARATION)4 TDPException (org.talend.dataprep.exception.TDPException)4 FolderRepository (org.talend.dataprep.folder.store.FolderRepository)4 Security (org.talend.dataprep.security.Security)4 Order (org.talend.dataprep.util.SortAndOrderHelper.Order)4 Sort (org.talend.dataprep.util.SortAndOrderHelper.Sort)4 MAX_VALUE (java.lang.Integer.MAX_VALUE)2 DecimalFormat (java.text.DecimalFormat)2 java.util (java.util)2 Collections.emptyList (java.util.Collections.emptyList)2 Function (java.util.function.Function)2 Predicate (java.util.function.Predicate)2