Search in sources :

Example 1 with NodeResource

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());
}
Also used : PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) Getter(lombok.Getter) GET(javax.ws.rs.GET) ProvInstancePriceRepository(org.ligoj.app.plugin.prov.dao.ProvInstancePriceRepository) Path(javax.ws.rs.Path) Autowired(org.springframework.beans.factory.annotation.Autowired) Function(java.util.function.Function) Supplier(java.util.function.Supplier) SecurityHelper(org.ligoj.bootstrap.core.security.SecurityHelper) MediaType(javax.ws.rs.core.MediaType) ServicePluginLocator(org.ligoj.app.resource.ServicePluginLocator) NodeResource(org.ligoj.app.resource.node.NodeResource) ProvInstanceTypeRepository(org.ligoj.app.plugin.prov.dao.ProvInstanceTypeRepository) Service(org.springframework.stereotype.Service) Map(java.util.Map) ProvStorageTypeRepository(org.ligoj.app.plugin.prov.dao.ProvStorageTypeRepository) LongTaskRunnerNode(org.ligoj.app.resource.node.LongTaskRunnerNode) DELETE(javax.ws.rs.DELETE) POST(javax.ws.rs.POST) NodeRepository(org.ligoj.app.dao.NodeRepository) Node(org.ligoj.app.model.Node) Transactional(javax.transaction.Transactional) ProvQuoteRepository(org.ligoj.app.plugin.prov.dao.ProvQuoteRepository) PageRequest(org.springframework.data.domain.PageRequest) ImportCatalogStatus(org.ligoj.app.plugin.prov.model.ImportCatalogStatus) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) OnNullReturn404(org.ligoj.bootstrap.core.resource.OnNullReturn404) ImportCatalogStatusRepository(org.ligoj.app.plugin.prov.dao.ImportCatalogStatusRepository) ProvLocationRepository(org.ligoj.app.plugin.prov.dao.ProvLocationRepository) Optional(java.util.Optional) ProvResource(org.ligoj.app.plugin.prov.ProvResource) NodeResource(org.ligoj.app.resource.node.NodeResource) LongTaskRunnerNode(org.ligoj.app.resource.node.LongTaskRunnerNode) Node(org.ligoj.app.model.Node) ImportCatalogStatus(org.ligoj.app.plugin.prov.model.ImportCatalogStatus) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Executors (java.util.concurrent.Executors)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 Transactional (javax.transaction.Transactional)1 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 PathParam (javax.ws.rs.PathParam)1 Produces (javax.ws.rs.Produces)1 MediaType (javax.ws.rs.core.MediaType)1 Getter (lombok.Getter)1 Slf4j (lombok.extern.slf4j.Slf4j)1 NodeRepository (org.ligoj.app.dao.NodeRepository)1 Node (org.ligoj.app.model.Node)1 ProvResource (org.ligoj.app.plugin.prov.ProvResource)1