Search in sources :

Example 1 with Parameter

use of org.ligoj.app.model.Parameter in project ligoj-api by ligoj.

the class ParameterResourceTest method getNotProvidedParametersWithDependencies.

@Test
public void getNotProvidedParametersWithDependencies() {
    // c_16->[c_10], c_10->[c_15, c8,c2], c8->c2, c2->[c7], c7->[c14]
    repository.findOneExpected("c_16").getDepends().add(repository.findOneExpected("c_10"));
    repository.findOneExpected("c_10").getDepends().add(repository.findOneExpected("c_15"));
    repository.findOneExpected("c_10").getDepends().add(repository.findOneExpected("c_8"));
    repository.findOneExpected("c_10").getDepends().add(repository.findOneExpected("c_2"));
    repository.findOneExpected("c_8").getDepends().add(repository.findOneExpected("c_2"));
    repository.findOneExpected("c_2").getDepends().add(repository.findOneExpected("c_7"));
    repository.findOneExpected("c_7").getDepends().add(repository.findOneExpected("c_14"));
    final List<ParameterVo> parameters = resource.getNotProvidedParameters("service:bt:jira:6", SubscriptionMode.LINK);
    // Dependency order check
    Assertions.assertTrue(indexOf("c_16", parameters) > indexOf("c_10", parameters));
    Assertions.assertTrue(indexOf("c_10", parameters) > indexOf("c_15", parameters));
    Assertions.assertTrue(indexOf("c_10", parameters) > indexOf("c_8", parameters));
    Assertions.assertTrue(indexOf("c_10", parameters) > indexOf("c_2", parameters));
    Assertions.assertTrue(indexOf("c_8", parameters) > indexOf("c_2", parameters));
    Assertions.assertTrue(indexOf("c_7", parameters) > indexOf("c_14", parameters));
    Assertions.assertTrue(indexOf("c_2", parameters) > indexOf("c_7", parameters));
    Assertions.assertTrue(indexOf("c_8", parameters) > indexOf("c_2", parameters));
    // Natural order check
    Assertions.assertTrue(indexOf("c_12", parameters) > indexOf("c_11", parameters));
    Assertions.assertTrue(indexOf("c_18", parameters) > indexOf("c_17", parameters));
    // Coverage only
    new Parameter().setDepends(Collections.emptyList());
}
Also used : Parameter(org.ligoj.app.model.Parameter) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Example 2 with Parameter

use of org.ligoj.app.model.Parameter 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 3 with Parameter

use of org.ligoj.app.model.Parameter in project ligoj-api by ligoj.

the class ParameterValueResourceTest method checkOwnership.

@Test
public void checkOwnership() {
    final Node node = new Node();
    node.setId("service:id");
    final Parameter parameter = new Parameter();
    parameter.setOwner(node);
    final Node node2 = new Node();
    node2.setId("service:id:sub");
    node2.setRefined(node);
    resource.checkOwnership(parameter, node2);
}
Also used : Node(org.ligoj.app.model.Node) Parameter(org.ligoj.app.model.Parameter) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Example 4 with Parameter

use of org.ligoj.app.model.Parameter in project ligoj-api by ligoj.

the class ParameterValueResourceTest method findInvalidJSonData.

@Test
public void findInvalidJSonData() {
    final Parameter parameter = parameterRepository.findOne("c_22");
    final ParameterValue parameterValueEntity = newParameterValue("'", parameter);
    Assertions.assertThrows(TechnicalException.class, () -> {
        resource.toVo(parameterValueEntity);
    });
}
Also used : ParameterValue(org.ligoj.app.model.ParameterValue) Parameter(org.ligoj.app.model.Parameter) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Example 5 with Parameter

use of org.ligoj.app.model.Parameter in project ligoj-api by ligoj.

the class ParameterValueResourceTest method findInteger.

@Test
public void findInteger() {
    final Parameter parameter = parameterRepository.findOne("c_4");
    final ParameterValue parameterValueEntity = newParameterValue("1", parameter);
    em.persist(parameterValueEntity);
    em.flush();
    final ParameterValueVo valueVo = resource.toVo(parameterValueEntity);
    Assertions.assertEquals(parameter.getId(), valueVo.getParameter().getId());
    Assertions.assertEquals(1, valueVo.getInteger().intValue());
    Assertions.assertNotNull(valueVo.getCreatedDate());
    Assertions.assertNotNull(valueVo.getCreatedBy());
}
Also used : ParameterValue(org.ligoj.app.model.ParameterValue) Parameter(org.ligoj.app.model.Parameter) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Aggregations

Parameter (org.ligoj.app.model.Parameter)22 Test (org.junit.jupiter.api.Test)20 AbstractAppTest (org.ligoj.app.AbstractAppTest)15 ParameterValue (org.ligoj.app.model.ParameterValue)14 ArrayList (java.util.ArrayList)7 Node (org.ligoj.app.model.Node)6 AbstractOrgTest (org.ligoj.app.resource.AbstractOrgTest)4 ParameterValueCreateVo (org.ligoj.app.resource.node.ParameterValueCreateVo)4 Subscription (org.ligoj.app.model.Subscription)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2 POST (javax.ws.rs.POST)2 NodeVo (org.ligoj.app.api.NodeVo)2 Collection (java.util.Collection)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