use of org.ligoj.app.resource.node.NodeResource in project plugin-prov by ligoj.
the class ImportCatalogResource method findAll.
/**
* Return the nodes and their catalog status.
*
* @return The nodes and their catalog status.
*/
@GET
@Path("catalog")
public List<CatalogVo> findAll() {
// Get all catalogs
final Map<String, ImportCatalogStatus> statuses = taskRepository.findAllVisible(securityHelper.getLogin()).stream().collect(Collectors.toMap(s -> s.getLocked().getId(), Function.identity()));
// Complete with nodes without populated catalog
final Page<Node> providers = nodeRepository.findAllVisible(securityHelper.getLogin(), "", ProvResource.SERVICE_KEY, null, 1, PageRequest.of(0, 100));
return providers.getContent().stream().sorted().map(NodeResource::toVo).map(n -> new CatalogVo(Optional.ofNullable(statuses.get(n.getId())).orElseGet(() -> {
// Create a mock catalog status
final ImportCatalogStatus status = new ImportCatalogStatus();
updateStats(status, n.getId());
return status;
}), n, locator.getResource(n.getId(), ImportCatalogService.class) != null, (int) repository.countByNode(n.getId()))).collect(Collectors.toList());
}
Aggregations