use of org.motechproject.osgi.web.ModuleRegistrationData in project motech by motech.
the class MenuBuilderTest method setUpToTestAccessControlledSubMenuLinks.
private void setUpToTestAccessControlledSubMenuLinks(boolean addSubMenuWithoutAccessControl) {
ModuleRegistrationData fooRegData = new ModuleRegistrationData("foo", "foo");
Map<String, SubmenuInfo> subMenuMap = new HashMap<>();
SubmenuInfo subMenuWithAccessForUserFoo = new SubmenuInfo("#/foo");
subMenuWithAccessForUserFoo.setRoleForAccess("foo");
SubmenuInfo subMenuWithAccessForUserBar = new SubmenuInfo("#/bar");
subMenuWithAccessForUserBar.setRoleForAccess("bar");
SubmenuInfo subMenuWithoutAccessControl = new SubmenuInfo("#/random");
subMenuMap.put("Foo", subMenuWithAccessForUserFoo);
subMenuMap.put("Bar", subMenuWithAccessForUserBar);
if (addSubMenuWithoutAccessControl) {
subMenuMap.put("Random", subMenuWithoutAccessControl);
}
fooRegData.setSubMenu(subMenuMap);
fooRegData.setBundle(bundle);
ModuleRegistrations modules = new ModuleRegistrations();
modules.setModulesWithSubMenu(Arrays.asList(fooRegData));
when(uiFrameworkService.getRegisteredModules()).thenReturn(modules);
RoleDto fooRole = new RoleDto("fooRole", Arrays.asList("foo"));
RoleDto someOtherRole = new RoleDto("someOtherRole", Arrays.asList("someOtherPermission"));
when(roleService.getRole("fooRole")).thenReturn(fooRole);
when(roleService.getRole("someOtherRole")).thenReturn(someOtherRole);
}
use of org.motechproject.osgi.web.ModuleRegistrationData 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;
}
use of org.motechproject.osgi.web.ModuleRegistrationData in project motech by motech.
the class UIServiceTrackers method addTrackerFor.
/**
* Creates a {@link UIServiceTracker} for the given bundle. The {@link org.motechproject.osgi.web.ModuleRegistrationData}
* from the provided Spring context of the bundle will be used for registering the UI.
* @param bundle the bundle to create the tracker for
* @param applicationContext the Spring context of the bundle
* @return the newly created {@link UIServiceTracker} instance
*/
public UIServiceTracker addTrackerFor(Bundle bundle, ApplicationContext applicationContext) {
if (!applicationContext.containsBean(MODULE_REGISTRATION_DATA)) {
LOGGER.warn("Bean moduleRegistrationData not found in {}", nullSafeSymbolicName(bundle));
return null;
}
LOGGER.debug("Bean moduleRegistrationData found for bundle {}", nullSafeSymbolicName(bundle));
ModuleRegistrationData moduleRegistrationData = (ModuleRegistrationData) applicationContext.getBean(MODULE_REGISTRATION_DATA);
final UIServiceTracker uiServiceTracker = new UIServiceTracker(bundle.getBundleContext(), moduleRegistrationData);
trackers.put(nullSafeSymbolicName(bundle), uiServiceTracker);
uiServiceTracker.start();
LOGGER.debug("UI Service Tracker registered for {}", nullSafeSymbolicName(bundle));
return uiServiceTracker;
}
use of org.motechproject.osgi.web.ModuleRegistrationData in project motech by motech.
the class MenuBuilder method serverModulesMenuSection.
private ModuleMenuSection serverModulesMenuSection(List<String> userRoles) {
ModuleMenuSection modulesSection = new ModuleMenuSection("server.modules", false);
for (ModuleRegistrationData moduleRegistrationData : getModulesWithoutSubMenu(userRoles)) {
String name = moduleRegistrationData.getModuleName();
String angularName = getAngularModuleName(moduleRegistrationData);
boolean needsAttention = moduleRegistrationData.isNeedsAttention();
// these menu items don't make use of urls, the name is sufficient
ModuleMenuLink link = new ModuleMenuLink(name, angularName, determineDefaultTab(moduleRegistrationData), needsAttention, moduleRegistrationData.getDocumentationUrl());
modulesSection.addLink(link);
}
return modulesSection;
}
Aggregations