use of org.talend.dataprep.api.folder.Folder in project data-prep by Talend.
the class APIClientTest method getFolderByPath.
public Folder getFolderByPath(String path) throws IOException {
InputStream inputStream = with().queryParam("path", path).get("/api/folders/search").asInputStream();
MappingIterator<Folder> foldersIterator = mapper.readerFor(Folder.class).readValues(inputStream);
List<Folder> folders = foldersIterator.readAll();
assertTrue(folders.size() == 1);
return folders.iterator().next();
}
use of org.talend.dataprep.api.folder.Folder in project data-prep by Talend.
the class APIPreparationConversionsTest method shouldDealWithRepeatedStepIds.
@Test
public void shouldDealWithRepeatedStepIds() {
// given
DataSetMetadata metadata = getDataSetMetadata("super dataset", 1001L);
setupHystrixCommand(DataSetGetMetadata.class, metadata);
final PreparationMessage preparation = getPreparationMessage(metadata.getId());
preparation.setSteps(asList(Step.ROOT_STEP, Step.ROOT_STEP));
Folder folder = getFolder("F-753854");
setupHystrixCommand(LocatePreparation.class, folder);
// when
final EnrichedPreparation actual = conversionService.convert(preparation, EnrichedPreparation.class);
// then
assertEquals(1, actual.getSteps().size());
assertEquals(Step.ROOT_STEP.id(), actual.getSteps().get(0));
}
use of org.talend.dataprep.api.folder.Folder in project data-prep by Talend.
the class FolderService method getFolderAndHierarchyById.
/**
* Get a folder metadata with its hierarchy
*
* @param id the folder id.
* @return the folder metadata with its hierarchy.
*/
@RequestMapping(value = "/folders/{id}", method = GET)
@ApiOperation(value = "Get folder by id", notes = "GET a folder by id")
@Timed
public FolderInfo getFolderAndHierarchyById(@PathVariable(value = "id") final String id) {
final Folder folder = folderRepository.getFolderById(id);
if (folder == null) {
throw new TDPException(FOLDER_NOT_FOUND, ExceptionContext.build().put("path", id));
}
final List<Folder> hierarchy = folderRepository.getHierarchy(folder);
return new FolderInfo(folder, hierarchy);
}
use of org.talend.dataprep.api.folder.Folder 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.Folder 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