Search in sources :

Example 1 with Plugin

use of fi.otavanopisto.pyramus.domainmodel.plugins.Plugin in project pyramus by otavanopisto.

the class PyramusServletContextListener method loadPlugins.

@SuppressWarnings("unchecked")
private void loadPlugins() {
    try {
        PluginRepositoryDAO pluginRepositoryDAO = DAOFactory.getInstance().getPluginRepositoryDAO();
        List<PluginRepository> pluginRepositories = pluginRepositoryDAO.listAll();
        PluginManager pluginManager = PluginManager.initialize(getClass().getClassLoader(), pluginRepositories);
        PluginDAO pluginDAO = DAOFactory.getInstance().getPluginDAO();
        List<Plugin> enabledPlugins = pluginDAO.listByEnabled(Boolean.TRUE);
        for (Plugin plugin : enabledPlugins) {
            try {
                pluginManager.loadPlugin(plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion());
            } catch (Exception e) {
                Logging.logException("Failed to load plugin: " + plugin.getGroupId() + "." + plugin.getArtifactId() + ":" + plugin.getVersion(), e);
            }
        }
        pluginManager.registerPlugins();
        // Load additional request mappings from plugins
        List<PluginDescriptor> plugins = pluginManager.getPlugins();
        for (PluginDescriptor plugin : plugins) {
            Map<String, Class<?>> pageRequestControllers = plugin.getPageRequestControllers();
            if (pageRequestControllers != null) {
                for (Map.Entry<String, Class<?>> entry : pageRequestControllers.entrySet()) {
                    String className = entry.getValue().getName();
                    Class<? extends RequestController> pageController = (Class<? extends RequestController>) Class.forName(className, false, pluginManager.getPluginsClassLoader());
                    RequestController oldController = RequestControllerMapper.getRequestController(entry.getKey() + ".page");
                    if (oldController != null) {
                        // Save masked controllers for extending existing functionality by calling
                        // the masked controller's .process()
                        RequestControllerMapper.mapController(entry.getKey(), ".page.masked", oldController);
                    }
                    RequestControllerMapper.mapController(entry.getKey(), ".page", pageController.newInstance());
                }
            }
            Map<String, Class<?>> jsonRequestControllers = plugin.getJSONRequestControllers();
            if (jsonRequestControllers != null) {
                for (Map.Entry<String, Class<?>> entry : jsonRequestControllers.entrySet()) {
                    String className = entry.getValue().getName();
                    Class<? extends RequestController> pageController = (Class<? extends RequestController>) Class.forName(className, false, pluginManager.getPluginsClassLoader());
                    RequestController oldController = RequestControllerMapper.getRequestController(entry.getKey() + ".json");
                    if (oldController != null) {
                        // Save masked controllers for extending existing functionality by calling
                        // the masked controller's .process()
                        RequestControllerMapper.mapController(entry.getKey(), ".json.masked", oldController);
                    }
                    RequestControllerMapper.mapController(entry.getKey(), ".json", pageController.newInstance());
                }
            }
            Map<String, Class<?>> binaryRequestControllers = plugin.getBinaryRequestControllers();
            if (binaryRequestControllers != null) {
                for (Map.Entry<String, Class<?>> entry : binaryRequestControllers.entrySet()) {
                    String className = entry.getValue().getName();
                    Class<? extends RequestController> pageController = (Class<? extends RequestController>) Class.forName(className, false, pluginManager.getPluginsClassLoader());
                    RequestController oldController = RequestControllerMapper.getRequestController(entry.getKey() + ".binary");
                    if (oldController != null) {
                        // Save masked controllers for extending existing functionality by calling
                        // the masked controller's .process()
                        RequestControllerMapper.mapController(entry.getKey(), ".binary.masked", oldController);
                    }
                    RequestControllerMapper.mapController(entry.getKey(), ".binary", pageController.newInstance());
                }
            }
        }
    } catch (Exception e) {
        Logging.logException("Plugins loading failed", e);
    }
    for (Webhook webhook : webhookDAO.listAll()) {
        webhooks.addWebhook(webhook.getUrl(), webhook.getSecret());
    }
    ;
}
Also used : PluginRepositoryDAO(fi.otavanopisto.pyramus.dao.plugins.PluginRepositoryDAO) PluginDAO(fi.otavanopisto.pyramus.dao.plugins.PluginDAO) PluginRepository(fi.otavanopisto.pyramus.domainmodel.plugins.PluginRepository) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) PluginManager(fi.otavanopisto.pyramus.plugin.PluginManager) PluginDescriptor(fi.otavanopisto.pyramus.plugin.PluginDescriptor) RequestController(fi.internetix.smvc.controllers.RequestController) Webhook(fi.otavanopisto.pyramus.domainmodel.webhooks.Webhook) Map(java.util.Map) Plugin(fi.otavanopisto.pyramus.domainmodel.plugins.Plugin)

Example 2 with Plugin

use of fi.otavanopisto.pyramus.domainmodel.plugins.Plugin in project pyramus by otavanopisto.

the class PluginsViewController method processForm.

@Override
public void processForm(PageRequestContext requestContext) {
    PluginRepositoryDAO pluginRepositoryDAO = DAOFactory.getInstance().getPluginRepositoryDAO();
    PluginDAO pluginDAO = DAOFactory.getInstance().getPluginDAO();
    PluginManager pluginManager = PluginManager.getInstance();
    List<PluginRepository> pluginRepositories = pluginRepositoryDAO.listAll();
    List<Plugin> plugins = pluginDAO.listAll();
    List<PluginBean> pluginBeans = new ArrayList<>(plugins.size());
    for (Plugin plugin : plugins) {
        String status;
        boolean loaded = pluginManager.isLoaded(plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion());
        boolean deletable = false;
        if (loaded) {
            if (plugin.getEnabled())
                status = Messages.getInstance().getText(requestContext.getRequest().getLocale(), "system.plugins.pluginsTableStatusLoaded");
            else
                status = Messages.getInstance().getText(requestContext.getRequest().getLocale(), "system.plugins.pluginsTableStatusUnloadOnRestart");
        } else {
            if (plugin.getEnabled())
                status = Messages.getInstance().getText(requestContext.getRequest().getLocale(), "system.plugins.pluginsTableStatusLoadOnRestart");
            else
                status = Messages.getInstance().getText(requestContext.getRequest().getLocale(), "system.plugins.pluginsTableStatusNotLoaded");
            deletable = true;
        }
        PluginBean pluginBean = new PluginBean(plugin.getId(), plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion(), plugin.getEnabled(), deletable, status);
        pluginBeans.add(pluginBean);
    }
    requestContext.getRequest().setAttribute("repositories", pluginRepositories);
    requestContext.getRequest().setAttribute("plugins", pluginBeans);
    /**
     *    Messages.getInstance().getText(requestContext.getRequest().getLocale(), "system.plugins.pluginsTableStatusNotLoaded");
     *    Messages.getInstance().getText(requestContext.getRequest().getLocale(), "system.plugins.pluginsTableStatusUnloadOnRestart");
     *    Messages.getInstance().getText(requestContext.getRequest().getLocale(), "system.plugins.pluginsTableStatusLoaded");
     */
    requestContext.setIncludeJSP("/templates/system/plugins.jsp");
}
Also used : PluginManager(fi.otavanopisto.pyramus.plugin.PluginManager) PluginRepositoryDAO(fi.otavanopisto.pyramus.dao.plugins.PluginRepositoryDAO) PluginDAO(fi.otavanopisto.pyramus.dao.plugins.PluginDAO) PluginRepository(fi.otavanopisto.pyramus.domainmodel.plugins.PluginRepository) ArrayList(java.util.ArrayList) Plugin(fi.otavanopisto.pyramus.domainmodel.plugins.Plugin)

Example 3 with Plugin

use of fi.otavanopisto.pyramus.domainmodel.plugins.Plugin in project pyramus by otavanopisto.

the class PluginDAO method listByEnabled.

public List<Plugin> listByEnabled(Boolean enabled) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Plugin> criteria = criteriaBuilder.createQuery(Plugin.class);
    Root<Plugin> root = criteria.from(Plugin.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.equal(root.get(Plugin_.enabled), enabled));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) Plugin(fi.otavanopisto.pyramus.domainmodel.plugins.Plugin)

Example 4 with Plugin

use of fi.otavanopisto.pyramus.domainmodel.plugins.Plugin in project pyramus by otavanopisto.

the class PluginDAO method findByGroupIdAndArtifactId.

public Plugin findByGroupIdAndArtifactId(String groupId, String artifactId) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Plugin> criteria = criteriaBuilder.createQuery(Plugin.class);
    Root<Plugin> root = criteria.from(Plugin.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(Plugin_.groupId), groupId), criteriaBuilder.equal(root.get(Plugin_.artifactId), artifactId)));
    return getSingleResult(entityManager.createQuery(criteria));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) Plugin(fi.otavanopisto.pyramus.domainmodel.plugins.Plugin)

Example 5 with Plugin

use of fi.otavanopisto.pyramus.domainmodel.plugins.Plugin in project pyramus by otavanopisto.

the class PluginDAO method create.

public Plugin create(String artifactId, String groupId, String version, Boolean enabled) {
    EntityManager entityManager = getEntityManager();
    Plugin plugin = new Plugin();
    plugin.setArtifactId(artifactId);
    plugin.setGroupId(groupId);
    plugin.setVersion(version);
    plugin.setEnabled(enabled);
    entityManager.persist(plugin);
    return plugin;
}
Also used : EntityManager(javax.persistence.EntityManager) Plugin(fi.otavanopisto.pyramus.domainmodel.plugins.Plugin)

Aggregations

Plugin (fi.otavanopisto.pyramus.domainmodel.plugins.Plugin)7 PluginDAO (fi.otavanopisto.pyramus.dao.plugins.PluginDAO)4 PluginRepositoryDAO (fi.otavanopisto.pyramus.dao.plugins.PluginRepositoryDAO)3 PluginRepository (fi.otavanopisto.pyramus.domainmodel.plugins.PluginRepository)3 EntityManager (javax.persistence.EntityManager)3 PluginManager (fi.otavanopisto.pyramus.plugin.PluginManager)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 RequestController (fi.internetix.smvc.controllers.RequestController)1 Webhook (fi.otavanopisto.pyramus.domainmodel.webhooks.Webhook)1 PluginDescriptor (fi.otavanopisto.pyramus.plugin.PluginDescriptor)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1