Search in sources :

Example 1 with FOLDER_NOT_FOUND

use of org.talend.dataprep.exception.error.FolderErrorCodes.FOLDER_NOT_FOUND 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)

Aggregations

Api (io.swagger.annotations.Api)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiParam (io.swagger.annotations.ApiParam)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors.toList (java.util.stream.Collectors.toList)1 Stream (java.util.stream.Stream)1 StreamSupport (java.util.stream.StreamSupport)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 HttpStatus (org.springframework.http.HttpStatus)1 PathVariable (org.springframework.web.bind.annotation.PathVariable)1 RequestBody (org.springframework.web.bind.annotation.RequestBody)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 DELETE (org.springframework.web.bind.annotation.RequestMethod.DELETE)1 GET (org.springframework.web.bind.annotation.RequestMethod.GET)1 PUT (org.springframework.web.bind.annotation.RequestMethod.PUT)1 RequestParam (org.springframework.web.bind.annotation.RequestParam)1 RestController (org.springframework.web.bind.annotation.RestController)1