use of org.pentaho.platform.api.engine.IPluginManager in project pentaho-platform by pentaho.
the class ActionUtilTest method resolveClassTestHappyPath.
@Test
public void resolveClassTestHappyPath() throws Exception {
// TODO: rewrite this test to read bean from spring rather than mocking it
String beanId = "ktr.backgroundAction";
Class<?> clazz = MyTestAction.class;
IPluginManager pluginManager = mock(IPluginManager.class);
PowerMockito.mockStatic(PentahoSystem.class);
BDDMockito.given(PentahoSystem.get(IPluginManager.class)).willReturn(pluginManager);
Mockito.doReturn(clazz).when(pluginManager).loadClass(anyString());
Class<?> aClass = ActionUtil.resolveActionClass(MyTestAction.class.getName(), beanId);
assertEquals(MyTestAction.class, aClass);
}
use of org.pentaho.platform.api.engine.IPluginManager in project pentaho-platform by pentaho.
the class ChartBeansSystemListener method initPlugins.
/**
* This methods looks in the chartbeans configuration file, and retrieves the prescribed list of chart plugins
* (renderers). For each defined renderer, the method then looks to the PluginManager to see if that renderer has been
* overridden. If it has, then the class defined in the PluginManager will be loaded IN PLACE OF the configuration
* file's class.
*
* @return list of available chart "plugin" (renderer) instances.
* @throws Exception
* if no chart plugins (renderers) are found.
*/
@SuppressWarnings("unchecked")
private List<IChartPlugin> initPlugins() throws Exception {
ArrayList<IChartPlugin> plugins = new ArrayList<IChartPlugin>();
HashMap<String, Object> pluginMap = new HashMap<String, Object>();
// $NON-NLS-1$
List<Element> nodes = PentahoSystem.getSystemSettings().getSystemSettings(configFile, "bean");
if (nodes == null || nodes.size() == 0) {
// $NON-NLS-1$
String msg = Messages.getInstance().getString("ChartBeansSystemListener.ERROR_0001_CONFIG_MISSING");
Logger.warn(ChartBeansSystemListener.class.getName(), msg);
throw new ChartSystemInitializationException(msg);
}
Element node;
String id;
Object plugin;
IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class);
for (int i = 0; i < nodes.size(); i++) {
node = nodes.get(i);
// $NON-NLS-1$
id = node.attribute("id").getText();
// $NON-NLS-1$
pluginMap.put(id, node.attribute("class").getText());
// Now let's see if there is a plugin overriding this engine...
if ((null != pluginManager) && (pluginManager.isBeanRegistered(id))) {
try {
plugin = pluginManager.getBean(id);
pluginMap.put(id, plugin);
} catch (PluginBeanException e) {
Logger.warn(ChartBeansSystemListener.class.getName(), Messages.getInstance().getString("ChartBeansSystemListener.ERROR_0002_PLUGINMANAGER_BEAN_MISSING", // $NON-NLS-1$
id), e);
}
}
}
for (Object clazz : pluginMap.values()) {
try {
if (clazz instanceof String) {
plugins.add((IChartPlugin) Class.forName(clazz.toString()).newInstance());
} else {
plugins.add((IChartPlugin) clazz);
}
} catch (Exception ex) {
Logger.warn(ChartBeansSystemListener.class.getName(), Messages.getInstance().getString("ChartBeansSystemListener.ERROR_0003_CLASS_CREATION_PROBLEM") + clazz, // $NON-NLS-1$
ex);
}
}
return plugins;
}
use of org.pentaho.platform.api.engine.IPluginManager in project pentaho-platform by pentaho.
the class ActionUtil method resolveActionClass.
/**
* Returns the {@link Class} that corresponds to the provides {@code actionClassName} and {@code beanId}.
*
* @param actionClassName the name of the class being resolved
* @param beanId the beanId of the class being resolved
* @param retryBeanInstantiationIfFailed re-trigger bean instantiation attempt, should it fail for some reason
* @return the {@link Class} that corresponds to the provides {@code actionClassName} and {@code beanId}
* @throws PluginBeanException when the plugin required to resolve the bean class from the {@code beanId} cannot be
* created
* @throws Exception when the required parameters are not provided
*/
static Class<?> resolveActionClass(final String actionClassName, final String beanId, final boolean retryBeanInstantiationIfFailed) throws PluginBeanException, ActionInvocationException {
Class<?> clazz = null;
if (StringUtils.isEmpty(beanId) && StringUtils.isEmpty(actionClassName)) {
throw new ActionInvocationException(Messages.getInstance().getErrorString("ActionUtil.ERROR_0001_REQUIRED_PARAM_MISSING", INVOKER_ACTIONCLASS, INVOKER_ACTIONID));
}
final long retryCount = (retryBeanInstantiationIfFailed ? RETRY_COUNT : 1);
// millis
final long retrySleepCount = (retryBeanInstantiationIfFailed ? RETRY_SLEEP_AMOUNT : 1);
for (int i = 0; i < retryCount; i++) {
try {
if (!StringUtils.isEmpty(beanId)) {
IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class);
clazz = pluginManager.loadClass(beanId);
if (clazz != null) {
return clazz;
}
}
// we will execute this only if the beanId is not provided, or if the beanId cannot be resolved
if (!StringUtils.isEmpty(actionClassName)) {
clazz = Class.forName(actionClassName);
return clazz;
}
} catch (Throwable t) {
try {
Thread.sleep(retrySleepCount);
} catch (InterruptedException ie) {
logger.info(ie.getMessage(), ie);
}
}
}
// which can typically happen at system startup
throw new ActionInvocationException(Messages.getInstance().getErrorString("ActionUtil.ERROR_0002_FAILED_TO_CREATE_ACTION", StringUtils.isEmpty(beanId) ? actionClassName : beanId));
}
use of org.pentaho.platform.api.engine.IPluginManager in project pentaho-platform by pentaho.
the class PluginManagerNotConfiguredIT method testBadConfig1.
public void testBadConfig1() {
startTest();
// $NON-NLS-1$
IPentahoSession session = new StandaloneSession("test user");
IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class, session);
assertNull(pluginManager);
finishTest();
}
use of org.pentaho.platform.api.engine.IPluginManager in project pentaho-platform by pentaho.
the class RepositoryResource method doExecuteDefault.
/**
* Takes a pathId to a file and generates a URI that represents the URL to call to generate content from that file.
*
* <p><b>Example Request:</b><br />
* GET pentaho/api/repos/public:steel%20wheels:Invoice%20(report).prpt/default
* </p>
*
* @param pathId @param pathId
*
* @return URI that represents a forwarding URL to execute to generate content from the file {pathId}.
*
* <p><b>Example Response:</b></p>
* <pre function="syntax.xml">
* This response does not contain data.
* </pre>
*/
@GET
@Path("{pathId : .+}/default")
@Produces({ WILDCARD })
@StatusCodes({ @ResponseCode(code = 303, condition = "Successfully get the resource."), @ResponseCode(code = 404, condition = "Failed to find the resource.") })
public Response doExecuteDefault(@PathParam("pathId") String pathId) throws FileNotFoundException, MalformedURLException, URISyntaxException {
String perspective = null;
StringBuffer buffer = null;
String url = null;
String path = FileResource.idToPath(pathId);
String extension = path.substring(path.lastIndexOf('.') + 1);
IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class, PentahoSessionHolder.getSession());
IContentInfo info = pluginManager.getContentTypeInfo(extension);
for (IPluginOperation operation : info.getOperations()) {
if (operation.getId().equalsIgnoreCase("RUN")) {
// $NON-NLS-1$
perspective = operation.getPerspective();
break;
}
}
if (perspective == null) {
perspective = GENERATED_CONTENT_PERSPECTIVE;
}
buffer = httpServletRequest.getRequestURL();
String queryString = httpServletRequest.getQueryString();
url = // $NON-NLS-1$
buffer.substring(0, buffer.lastIndexOf("/") + 1) + perspective + ((queryString != null && queryString.length() > 0) ? "?" + httpServletRequest.getQueryString() : "");
return Response.seeOther((new URL(url)).toURI()).build();
}
Aggregations