use of org.ligoj.app.model.Subscription in project ligoj-api by ligoj.
the class TestAbstractConfiguredServicePlugin method prepareMock.
@SuppressWarnings("unchecked")
@BeforeEach
public void prepareMock() {
resource = new AbstractConfiguredServicePlugin<>() {
@Override
public String getKey() {
return "key";
}
@Override
public Object getConfiguration(int subscription) {
return configuration;
}
};
resource.subscriptionRepository = Mockito.mock(SubscriptionRepository.class);
resource.projectRepository = Mockito.mock(ProjectRepository.class);
resource.securityHelper = Mockito.mock(SecurityHelper.class);
repository = Mockito.mock(RestRepository.class);
configuration = Mockito.mock(PluginConfiguration.class);
configurable = Mockito.mock(NamedConfigurable.class);
subscription = new Subscription();
subscription.setId(33);
project = new Project();
project.setId(44);
subscription.setProject(project);
Mockito.when(resource.securityHelper.getLogin()).thenReturn("junit");
Mockito.when(configurable.getConfiguration()).thenReturn(configuration);
Mockito.when(configurable.getId()).thenReturn(1);
Mockito.when(configurable.getName()).thenReturn("my-name");
Mockito.when(configuration.getSubscription()).thenReturn(subscription);
Mockito.when(resource.subscriptionRepository.findOneExpected(33)).thenReturn(subscription);
Mockito.when(resource.projectRepository.findOneVisible(44, "junit")).thenReturn(project);
Mockito.when(repository.findOneExpected(1)).thenReturn(configurable);
Mockito.when(repository.findAllBy("configuration.subscription.id", subscription.getId(), new String[] { "name" }, "my-name")).thenReturn(Collections.singletonList(configurable));
}
use of org.ligoj.app.model.Subscription in project ligoj-api by ligoj.
the class ProjectResource method delete.
/**
* Delete entity. Should be protected with RBAC.
*
* @param id
* The entity identifier.
*/
@DELETE
@Path("{id:\\d+}")
public void delete(@PathParam("id") final int id) throws Exception {
final Project project = findOneVisible(id, Function.identity());
for (final Subscription subscription : project.getSubscriptions()) {
subscriptionResource.delete(subscription.getId());
}
repository.delete(project);
}
use of org.ligoj.app.model.Subscription in project ligoj-api by ligoj.
the class SubscriptionResource method getConfiguration.
/**
* Return tools specific configuration. Only non secured parameters are returned.
*
* @param id
* The subscription identifier.
* @return tools specific configuration.
* @throws Exception
* When the configuration gathering fails. Managed at JAX-RS level.
*/
@GET
@Path("{id:\\d+}/configuration")
@org.springframework.transaction.annotation.Transactional(readOnly = true)
public ConfigurationVo getConfiguration(@PathParam("id") final int id) throws Exception {
// Copy subscription details
final Subscription entity = checkVisibleSubscription(id);
final ConfigurationVo vo = new ConfigurationVo();
vo.setNode(NodeResource.toVo(entity.getNode()));
vo.setParameters(getNonSecuredParameters(id));
vo.setSubscription(id);
vo.setProject(DescribedBean.clone(entity.getProject()));
// Get specific configuration
final ConfigurablePlugin servicePlugin = locator.getResource(vo.getNode().getId(), ConfigurablePlugin.class);
if (servicePlugin != null) {
// Specific configuration is available
vo.setConfiguration(servicePlugin.getConfiguration(id));
}
return vo;
}
use of org.ligoj.app.model.Subscription in project ligoj-api by ligoj.
the class NodeResource method checkNodeSubscriptions.
/**
* Check the subscriptions of each subscription related to given node.
*/
private void checkNodeSubscriptions(final Node node, final Map<String, String> nodeParameters, final Map<Subscription, Map<String, String>> subscriptions) {
int counter = 0;
for (final Entry<Subscription, Map<String, String>> subscription : subscriptions.entrySet()) {
// For each subscription, check status
log.info("Check all subscriptions of node {} : {}/{} ...", node.getId(), counter + 1, subscriptions.size());
final Map<String, String> parameters = new HashMap<>(nodeParameters);
parameters.putAll(subscription.getValue());
final NodeStatus subscriptionStatus = self.checkSubscriptionStatus(subscription.getKey(), parameters).getStatus();
eventResource.registerEvent(subscription.getKey(), EventType.STATUS, subscriptionStatus.name());
counter++;
}
}
use of org.ligoj.app.model.Subscription 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