/** * Get model for showing plugin configuration * * @param configuration current plugin configuration * @return ModelAndView */ private ModelAndView getModel(PluginConfiguration configuration) { Map<String, String> labels = new HashMap<>(); List<Plugin> plugins = pluginLoader.getPlugins(new NameFilter(configuration.getName())); if (!plugins.isEmpty()) { Plugin plugin = plugins.get(0); if (plugin != null) { labels = translatePropertiesLabels(configuration.getProperties(), plugin); } } return new ModelAndView("plugin/pluginConfiguration") .addObject("pluginConfiguration", configuration) .addObject("labelsTranslation", labels); }
/** * Update the configuration of plugin * * @param newConfiguration new configuration for plugin * @return redirect to the page of plugin configuration * @throws NotFoundException if configured plugin wasn't found */ @RequestMapping(value = "/configure/{name}", method = RequestMethod.POST) public ModelAndView updateConfiguration(Model model, @ModelAttribute PluginConfiguration newConfiguration) throws NotFoundException { long componentId = getForumComponentId(); try { pluginService.updateConfiguration(newConfiguration, componentId); } catch (UnexpectedErrorException ex) { model.addAttribute("error", ex.getCause().getLocalizedMessage()); model.addAttribute("errorInformation", ExceptionUtils.getFullStackTrace(ex.getCause())); model.addAttribute("pluginConfiguration", newConfiguration); return getModel(newConfiguration); } return new ModelAndView("redirect:/plugins/configure/" + newConfiguration.getName()); }
@Override public Plugin getPluginById(String pluginId, PluginFilter... filters) throws NotFoundException { PluginConfiguration conf = getDao().get(Long.valueOf(pluginId)); Plugin plugin = findPluginByName(pLuginLoader.getPlugins(filters), conf.getName()); if (plugin == null) { throw new NotFoundException("Plugin with Id '" + pluginId + "' not found."); } return plugin; }
/** * {@inheritDoc} */ @Override @PreAuthorize("hasPermission(#forumComponentId, 'COMPONENT', 'GeneralPermission.ADMIN')") public void updateConfiguration(PluginConfiguration pluginConfiguration, long forumComponentId) throws NotFoundException, UnexpectedErrorException { String name = pluginConfiguration.getName(); List<Plugin> pluginsList = pLuginLoader.getPlugins(); Plugin willBeConfigured = findPluginByName(pluginsList, name); if (willBeConfigured == null) { throw new NotFoundException("Plugin " + name + " is not loaded"); } willBeConfigured.configure(pluginConfiguration); try { saveNewPluginConfiguration(pluginConfiguration); } catch (RuntimeException ex) { throw new UnexpectedErrorException(ex); } }