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));
}
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;
}
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);
}
}
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())));
}
Aggregations