org.scijava.module.process.PreprocessorPlugin Java Examples

The following examples show how to use org.scijava.module.process.PreprocessorPlugin. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ModulesResource.java    From imagej-server with Apache License 2.0 4 votes vote down vote up
/**
 * Gets more detailed information of a module with the given ID.
 *
 * @param id ID of the module
 * @return More detailed information of the module with the given ID
 * @throws JsonProcessingException
 */
@GET
@Path("{id}")
public String getWidget(@PathParam("id") final String id)
	throws JsonProcessingException
{
	final ModuleInfo info = moduleCache.getOrDefault(id, null);
	if (info == null) {
		final String msg = String.format("Module %s does not exist", id);
		throw new WebApplicationException(msg, Status.NOT_FOUND);
	}

	// Check if we're dealing with Command information
	if (!(info instanceof CommandInfo)) {
		// TODO - decide what to do if this happens.
		throw new IllegalArgumentException("Object is not an instance of " + CommandInfo.class.getName());
	}

	// Create a transient instance of the module, so we can do some
	// selective preprocessing. This is necessary to determine which
	// inputs are still unresolved at the time of user input harvesting,
	// as well as what their current starting values are.
	final Module module = moduleService.createModule(info);

	// Get the complete list of preprocessors.
	final List<PluginInfo<PreprocessorPlugin>> allPPs =
		pluginService.getPluginsOfType(PreprocessorPlugin.class);

	// Filter the list to only those which run _before_ input harvesting.
	final List<PluginInfo<PreprocessorPlugin>> goodPPs = allPPs.stream() //
		.filter(ppInfo -> ppInfo.getPriority() > InputHarvester.PRIORITY) //
		.collect(Collectors.toList());

	// Execute all of these "good" preprocessors to prep the module correctly.
	for (final ModulePreprocessor p : pluginService.createInstances(goodPPs)) {
		p.process(module);
		if (p.isCanceled()) {
			// TODO - decide what to do if this happens.
		}
	}

	// Create a WebCommandInfo instance and parse it (resolved inputs will be identified during the process)
	return jsonService.parseObject(new WebCommandInfo((CommandInfo)info, module));
}