use of org.talend.dataprep.api.folder.Folder in project data-prep by Talend.
the class RenameDataSetsWithFolderPath method run.
/**
* @see UpgradeTask#run()
*/
@Override
public void run() {
final Stream<DataSetMetadata> datasets = dataSetMetadataRepository.list();
datasets.forEach(dataset -> {
final Folder folder = folderRepository.locateEntry(dataset.getId(), FolderContentType.DATASET);
// skip home folder
if (folder != null && !StringUtils.equals("/", folder.getPath())) {
String newName = dataset.getName() + " - " + StringUtils.strip(folder.getPath(), "/");
dataset.setName(newName);
dataSetMetadataRepository.save(dataset);
LOG.debug("dataset #{} renamed to {}", dataset.getId(), newName);
} else {
LOG.debug("dataset #{} not renamed since it's in the user home folder", dataset.getId());
}
});
}
use of org.talend.dataprep.api.folder.Folder 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.Folder in project data-prep by Talend.
the class FileSystemFolderRepository method children.
@Override
public Stream<Folder> children(String parentId) {
final FolderPath parentDpPath = fromId(parentId);
try {
Path folderPath;
if (parentDpPath != null) {
folderPath = pathsConverter.toPath(parentDpPath);
} else {
folderPath = pathsConverter.getRootFolder();
}
Stream<Folder> children;
if (Files.notExists(folderPath)) {
children = Stream.empty();
} else {
children = //
Files.list(folderPath).map(p -> toFolderIfDirectory(p, security.getUserId())).filter(Objects::nonNull);
}
return children;
} catch (IOException e) {
throw new TDPException(UNABLE_TO_LIST_FOLDER_CHILDREN, e, build().put("path", parentDpPath == null ? null : parentDpPath.serializeAsString()));
}
}
use of org.talend.dataprep.api.folder.Folder in project data-prep by Talend.
the class SetStepRowMetadata method setStepRowMetadata.
/**
* Update the given preparation's steps with row metadata.
*
* @param preparation the preparation.
* @param currentProcessingNumber the number of the current preparation.
* @param total the total number of preparation.
*/
private void setStepRowMetadata(PersistentPreparation preparation, AtomicLong currentProcessingNumber, long total) {
LOGGER.info("[{}/{}] preparation #{} migration starting...", currentProcessingNumber.addAndGet(1), total, preparation.getId());
// Check if preparation is accessible to end user
final Folder folder = folderRepository.locateEntry(preparation.id(), PREPARATION);
if (folder == null) {
LOGGER.warn("Preparation {} does not belong to a folder, skip migration (not accessible to user).", preparation.getName());
return;
}
// Run preparation
final ExportParameters exportParameters = new ExportParameters();
exportParameters.setPreparationId(preparation.getId());
exportParameters.setDatasetId(preparation.getDataSetId());
exportParameters.setExportType("JSON");
// just process the preparation, the transformation service will automatically update the steps with row metadata
try (NullOutputStream outputStream = new NullOutputStream()) {
service.execute(exportParameters).writeTo(outputStream);
} catch (Throwable e) {
LOGGER.warn("Error processing preparation {} (#{}), semantic categories are not properly stored and may change if you change them using the data quality command line", preparation.getName(), preparation.getId());
LOGGER.debug("Here is the stacktrace", e);
}
LOGGER.info("[{}/{}] preparation #{} done", currentProcessingNumber.get(), total, preparation.getId());
}
use of org.talend.dataprep.api.folder.Folder in project data-prep by Talend.
the class AddAllPreparationsToHomeTest method shouldAddAllPreparationsToHome.
@Test
public void shouldAddAllPreparationsToHome() throws Exception {
// given
final String homeFolderId = folderRepository.getHome().getId();
// when
task.run();
// then
final Stream<Preparation> preparations = preparationRepository.list(Preparation.class);
preparations.forEach(p -> {
final Folder folder = folderRepository.locateEntry(p.getId(), PREPARATION);
assertEquals(homeFolderId, folder.getId());
});
}
Aggregations