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