Search in sources :

Example 1 with ServicePlugin

use of org.ligoj.app.api.ServicePlugin in project ligoj-api by ligoj.

the class ServicePluginLocator method getResource.

/**
 * Return the plug-in from the service key.
 *
 * @param service
 *            the service name.
 * @param requiredType
 *            The required resource class. For sample
 *            <code>ServicePlugin.class</code>
 * @param <T>
 *            The required resource type. For sample
 *            <code>ServicePlugin</code>
 * @return the plug-in from the service key. <code>null</code> if not found.
 */
@SuppressWarnings("unchecked")
public <T> T getResource(final String service, final Class<T> requiredType) {
    if (service == null) {
        // No service, may be from the recursive call ...
        return null;
    }
    // Search the resource
    final String name = self.getResourceName(service);
    if (name == null) {
        // Bean does not exists
        return null;
    }
    // Check the type
    final ServicePlugin bean = SpringUtils.getApplicationContext().getBean(name, ServicePlugin.class);
    if (requiredType.isInstance(bean)) {
        return (T) bean;
    }
    // Try the parent
    return getResource(getParent(bean.getKey()), requiredType);
}
Also used : ServicePlugin(org.ligoj.app.api.ServicePlugin)

Example 2 with ServicePlugin

use of org.ligoj.app.api.ServicePlugin in project ligoj-api by ligoj.

the class AbstractLockedResource method deleteWithTasks.

/**
 * Delete all tasks related the given entity and check there is no running
 * tasks.
 *
 * @param node
 *            The related node's identifier owning the locked resource.
 * @param id
 *            The entity's identifier being deleted.
 * @param deleteRemoteData
 *            When <code>true</code>, remote data will be also destroyed.
 * @throws Exception When any delete fails. Managed at upper level.
 */
public void deleteWithTasks(final String node, final I id, final boolean deleteRemoteData) throws Exception {
    // Delegate the deletion
    ServicePlugin plugin = locator.getResource(node);
    while (plugin != null) {
        // Pre-check for long task
        deleteTasks(plugin, id);
        delete(plugin, id, deleteRemoteData);
        plugin = locator.getResource(locator.getParent(plugin.getKey()));
    }
}
Also used : ServicePlugin(org.ligoj.app.api.ServicePlugin)

Aggregations

ServicePlugin (org.ligoj.app.api.ServicePlugin)2