Search in sources :

Example 1 with NodeVo

use of org.ligoj.app.api.NodeVo in project ligoj-api by ligoj.

the class NodeResource method toVoLight.

/**
 * {@link Node} JPA to VO object transformer without refined informations.
 *
 * @param entity
 *            Source entity.
 * @return The corresponding VO object without recursive redefined reference.
 */
public static NodeVo toVoLight(final Node entity) {
    final NodeVo vo = new NodeVo();
    NamedBean.copy(entity, vo);
    vo.setMode(entity.getMode());
    vo.setUiClasses(entity.getUiClasses());
    return vo;
}
Also used : NodeVo(org.ligoj.app.api.NodeVo)

Example 2 with NodeVo

use of org.ligoj.app.api.NodeVo in project ligoj-api by ligoj.

the class NodeResource method toVoParameter.

/**
 * {@link Node} JPA to business object transformer with parameters.
 *
 * @param entity
 *            Source entity.
 * @return The corresponding VO object with resources and without recursive parent reference.
 */
private static NodeVo toVoParameter(final Node entity) {
    final NodeVo vo = toVoLight(entity);
    vo.setParameters(new HashMap<>());
    vo.setTag(entity.getTag());
    vo.setTagUiClasses(entity.getTagUiClasses());
    return vo;
}
Also used : NodeVo(org.ligoj.app.api.NodeVo)

Example 3 with NodeVo

use of org.ligoj.app.api.NodeVo in project ligoj-api by ligoj.

the class NodeResource method toVoParameters.

/**
 * JPA {@link Node} associated to {@link ParameterValue} to detailed {@link NodeVo} converter. This not a one to one
 * {@link Function}.
 *
 * @param nodesAndValues
 *            Nodes with values.
 * @return The corresponding VO objects with recursive redefined reference.
 */
public static Map<String, NodeVo> toVoParameters(final List<Object[]> nodesAndValues) {
    // Build the nodes
    final Map<String, NodeVo> nodes = new HashMap<>();
    final Map<String, Node> entities = new HashMap<>();
    for (final Object[] resultSet : nodesAndValues) {
        final Node node = (Node) resultSet[0];
        final NodeVo vo = nodes.computeIfAbsent(node.getId(), id -> {
            // Build the first encountered parameter for this node
            entities.put(id, node);
            return toVoParameter(node);
        });
        // Copy the parameter value if present
        Optional.ofNullable((ParameterValue) resultSet[1]).ifPresent(v -> vo.getParameters().put(v.getParameter().getId(), ParameterValueResource.parseValue(v, new ParameterValueVo())));
    }
    // Complete the hierarchy
    entities.entrySet().stream().filter(entry -> entry.getValue().isRefining()).forEach(entry -> {
        // Complete the hierarchy for this node
        final NodeVo node = nodes.get(entry.getKey());
        final NodeVo parent = nodes.get(entry.getValue().getRefined().getId());
        node.setRefined(parent);
        node.getParameters().putAll(parent.getParameters());
    });
    return nodes;
}
Also used : Parameter(org.ligoj.app.model.Parameter) Produces(javax.ws.rs.Produces) BiFunction(java.util.function.BiFunction) Path(javax.ws.rs.Path) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) ValidationJsonException(org.ligoj.bootstrap.core.validation.ValidationJsonException) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) SubscriptionMode(org.ligoj.app.api.SubscriptionMode) DataTableAttributes(org.ligoj.bootstrap.core.json.datatable.DataTableAttributes) Map(java.util.Map) ListUtils(org.apache.commons.collections4.ListUtils) DefaultValue(javax.ws.rs.DefaultValue) Subscription(org.ligoj.app.model.Subscription) DELETE(javax.ws.rs.DELETE) Context(javax.ws.rs.core.Context) NodeRepository(org.ligoj.app.dao.NodeRepository) NodeStatus(org.ligoj.app.api.NodeStatus) Transactional(javax.transaction.Transactional) Collection(java.util.Collection) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) OnNullReturn404(org.ligoj.bootstrap.core.resource.OnNullReturn404) Entry(java.util.Map.Entry) Optional(java.util.Optional) UriInfo(javax.ws.rs.core.UriInfo) TableItem(org.ligoj.bootstrap.core.json.TableItem) ParameterRepository(org.ligoj.app.dao.ParameterRepository) LongTaskRunner(org.ligoj.app.resource.plugin.LongTaskRunner) PathParam(javax.ws.rs.PathParam) CacheRemoveAll(javax.cache.annotation.CacheRemoveAll) GET(javax.ws.rs.GET) ToolPlugin(org.ligoj.app.api.ToolPlugin) HashMap(java.util.HashMap) NamedBean(org.ligoj.bootstrap.core.NamedBean) Scheduled(org.springframework.scheduling.annotation.Scheduled) EventRepository(org.ligoj.app.dao.EventRepository) Function(java.util.function.Function) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) SubscriptionRepository(org.ligoj.app.dao.SubscriptionRepository) SecurityHelper(org.ligoj.bootstrap.core.security.SecurityHelper) EnumUtils(org.apache.commons.lang3.EnumUtils) Service(org.springframework.stereotype.Service) ParameterValue(org.ligoj.app.model.ParameterValue) NodeVo(org.ligoj.app.api.NodeVo) PaginationJson(org.ligoj.bootstrap.core.json.PaginationJson) POST(javax.ws.rs.POST) Node(org.ligoj.app.model.Node) SubscriptionStatusWithData(org.ligoj.app.api.SubscriptionStatusWithData) EventType(org.ligoj.app.model.EventType) BusinessException(org.ligoj.bootstrap.core.resource.BusinessException) CacheResult(javax.cache.annotation.CacheResult) ServicePlugin(org.ligoj.app.api.ServicePlugin) PUT(javax.ws.rs.PUT) ParameterValue(org.ligoj.app.model.ParameterValue) HashMap(java.util.HashMap) Node(org.ligoj.app.model.Node) NodeVo(org.ligoj.app.api.NodeVo)

Example 4 with NodeVo

use of org.ligoj.app.api.NodeVo in project ligoj-api by ligoj.

the class NodeResourceTest method getServices.

@Test
public void getServices() {
    final List<NodeVo> resources = resource.findAll(newUriInfo(), null, "service", null, -1).getData();
    Assertions.assertEquals(10, resources.size());
    final NodeVo service = resources.get(0);
    Assertions.assertEquals(BugTrackerResource.SERVICE_KEY, service.getId());
    Assertions.assertEquals("Bug Tracker", service.getName());
    Assertions.assertNull(service.getRefined());
    Assertions.assertEquals(SubscriptionMode.LINK, service.getMode());
    Assertions.assertEquals("fa fa-bug", service.getUiClasses());
    final NodeVo service2 = resources.get(1);
    Assertions.assertEquals(BuildResource.SERVICE_KEY, service2.getId());
    Assertions.assertEquals("Build", service2.getName());
    Assertions.assertNull(service2.getRefined());
    Assertions.assertEquals(SubscriptionMode.LINK, service2.getMode());
    final NodeVo service3 = resources.get(2);
    Assertions.assertEquals(IdentityResource.SERVICE_KEY, service3.getId());
    Assertions.assertEquals("Identity management", service3.getName());
    Assertions.assertEquals("fa fa-key", service3.getUiClasses());
    Assertions.assertNull(service3.getRefined());
    Assertions.assertEquals(SubscriptionMode.CREATE, service3.getMode());
    final NodeVo service4 = resources.get(3);
    Assertions.assertEquals(KmResource.SERVICE_KEY, service4.getId());
    Assertions.assertNull(service4.getRefined());
    Assertions.assertEquals(SubscriptionMode.LINK, service4.getMode());
    final NodeVo service5 = resources.get(4);
    Assertions.assertEquals(KpiResource.SERVICE_KEY, service5.getId());
    Assertions.assertEquals("KPI Collection", service5.getName());
    Assertions.assertNull(service5.getRefined());
    Assertions.assertEquals(SubscriptionMode.LINK, service5.getMode());
}
Also used : NodeVo(org.ligoj.app.api.NodeVo) Test(org.junit.jupiter.api.Test) AbstractAppTest(org.ligoj.app.AbstractAppTest)

Example 5 with NodeVo

use of org.ligoj.app.api.NodeVo in project ligoj-api by ligoj.

the class NodeResourceTest method findAllByParentFilterModeAkkAcceptLink.

@Test
public void findAllByParentFilterModeAkkAcceptLink() {
    final List<NodeVo> resources = resource.findAll(newUriInfo(), null, "service:scm:git", SubscriptionMode.LINK, -1).getData();
    Assertions.assertEquals(1, resources.size());
    final NodeVo service = resources.get(0);
    Assertions.assertEquals("service:scm:git:dig", service.getId());
    Assertions.assertEquals("git DIG", service.getName());
    Assertions.assertEquals("service:scm:git", service.getRefined().getId());
    Assertions.assertEquals("fab fa-git", service.getUiClasses());
}
Also used : NodeVo(org.ligoj.app.api.NodeVo) Test(org.junit.jupiter.api.Test) AbstractAppTest(org.ligoj.app.AbstractAppTest)

Aggregations

NodeVo (org.ligoj.app.api.NodeVo)16 Test (org.junit.jupiter.api.Test)10 AbstractAppTest (org.ligoj.app.AbstractAppTest)9 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Node (org.ligoj.app.model.Node)2 Parameter (org.ligoj.app.model.Parameter)2 ParameterValue (org.ligoj.app.model.ParameterValue)2 Subscription (org.ligoj.app.model.Subscription)2 SubscriptionVo (org.ligoj.app.resource.subscription.SubscriptionVo)2 Collection (java.util.Collection)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1 BiFunction (java.util.function.BiFunction)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 CacheRemoveAll (javax.cache.annotation.CacheRemoveAll)1