Search in sources :

Example 21 with Parameter

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

the class SubscriptionResourceTest method checkMandatoryParametersMandatory.

@Test
public void checkMandatoryParametersMandatory() {
    final List<ParameterValueCreateVo> parameters = new ArrayList<>();
    final List<Parameter> acceptedParameters = new ArrayList<>();
    final Parameter parameter = new Parameter();
    parameter.setId("p");
    parameter.setMandatory(true);
    acceptedParameters.add(parameter);
    Assertions.assertThrows(ValidationJsonException.class, () -> {
        resource.checkMandatoryParameters(parameters, acceptedParameters, null);
    });
}
Also used : ParameterValueCreateVo(org.ligoj.app.resource.node.ParameterValueCreateVo) ArrayList(java.util.ArrayList) Parameter(org.ligoj.app.model.Parameter) Test(org.junit.jupiter.api.Test) AbstractOrgTest(org.ligoj.app.resource.AbstractOrgTest)

Example 22 with Parameter

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

the class SubscriptionResource method create.

/**
 * Create subscription.
 *
 * @param vo
 *            the subscription.
 * @return the created {@link Subscription}.
 * @throws Exception
 *             When the creat fails. Managed at JAX-RS level.
 */
@POST
public int create(final SubscriptionEditionVo vo) throws Exception {
    // Validate entities
    final Project project = checkVisibleProject(vo.getProject());
    checkManagedProject(vo.getProject());
    final Node node = checkManagedNodeForSubscription(vo.getNode());
    final List<Parameter> acceptedParameters = checkInputParameters(vo);
    // Create subscription and parameters that would be removed in case of
    // roll-back because of invalid parameters
    final Subscription entity = toEntity(vo, project, node);
    // Expose the real entity for plug-in since we have loaded it
    entity.setProject(project);
    // Save this subscription in the transaction
    repository.saveAndFlush(entity);
    parameterValueResource.create(vo.getParameters(), entity);
    // Delegate to the related plug-in the next process
    delegateToPlugin(vo, entity);
    // Check again the parameters in the final state
    checkMandatoryParameters(vo.getParameters(), acceptedParameters, SubscriptionMode.CREATE);
    log.info("Subscription of project {} to service {}", vo.getProject(), vo.getNode());
    return entity.getId();
}
Also used : Project(org.ligoj.app.model.Project) Node(org.ligoj.app.model.Node) Parameter(org.ligoj.app.model.Parameter) Subscription(org.ligoj.app.model.Subscription) POST(javax.ws.rs.POST)

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