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;
}
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;
}
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;
}
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());
}
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());
}
Aggregations