Search in sources :

Example 1 with ModuleConfig

use of org.motechproject.server.web.dto.ModuleConfig in project motech by motech.

the class ModuleController method restDocConfig.

private ModuleConfig restDocConfig() {
    ModuleConfig config = new ModuleConfig();
    config.setName("rest-docs");
    config.setTemplate("../server/resources/partials/rest-docs-index.html");
    config.setScript("../server/resources/rest-docs/rest-docs-app.js");
    return config;
}
Also used : ModuleConfig(org.motechproject.server.web.dto.ModuleConfig)

Example 2 with ModuleConfig

use of org.motechproject.server.web.dto.ModuleConfig in project motech by motech.

the class ModuleController method addConfig.

private void addConfig(List<ModuleConfig> configuration, String name, String script, String template, String css) {
    ModuleConfig config = new ModuleConfig();
    config.setName(name);
    config.setScript(script);
    config.setTemplate(template);
    config.setCss(css);
    if (isNotBlank(name)) {
        if (containsConfig(configuration, name)) {
            throw new IllegalStateException("The angular module name have to be unique");
        }
        configuration.add(config);
    }
}
Also used : ModuleConfig(org.motechproject.server.web.dto.ModuleConfig)

Example 3 with ModuleConfig

use of org.motechproject.server.web.dto.ModuleConfig in project motech by motech.

the class ModuleController method getConfig.

@RequestMapping(value = "/module/config", method = RequestMethod.GET)
@ResponseBody
public List<ModuleConfig> getConfig() throws IOException {
    List<ModuleConfig> configuration = new ArrayList<>();
    for (Bundle bundle : bundleContext.getBundles()) {
        ModuleRegistrationData data = uiFrameworkService.getModuleDataByBundle(bundle);
        if (null != data) {
            Map<String, String> scripts = findScripts(bundle);
            for (Map.Entry<String, String> script : scripts.entrySet()) {
                addConfig(configuration, script.getKey(), getPath(data, script.getValue()));
            }
            List<String> angularModules = data.getAngularModules();
            String name = isEmpty(angularModules) ? null : angularModules.get(0);
            List<URL> css = filterByClass(URL.class, bundle.findEntries("/webapp/css/", "*.css", true));
            String cssPath = null;
            if (!css.isEmpty() && !bundle.getSymbolicName().equalsIgnoreCase("org.motechproject.motech-platform-server-bundle")) {
                cssPath = getPath(data, getCSSPath(css.get(0)));
            }
            addConfig(configuration, name, getPath(data, "/js/app.js"), data.getUrl(), cssPath);
        }
    }
    // rest documentation han an Angular module within server-bundle
    configuration.add(restDocConfig());
    return configuration;
}
Also used : Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) ModuleConfig(org.motechproject.server.web.dto.ModuleConfig) ModuleRegistrationData(org.motechproject.osgi.web.ModuleRegistrationData) HashMap(java.util.HashMap) Map(java.util.Map) URL(java.net.URL) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ModuleConfig (org.motechproject.server.web.dto.ModuleConfig)3 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ModuleRegistrationData (org.motechproject.osgi.web.ModuleRegistrationData)1 Bundle (org.osgi.framework.Bundle)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1