private static Application<Gadget> toGadget(UIGadget uiGadget) { Application<Gadget> app = Application.createGadgetApplication(uiGadget.getStorageId()); app.setState(uiGadget.getState()); app.setProperties(uiGadget.getProperties()); app.setStorageName(uiGadget.getStorageName()); return app; }
@Override protected void afterSecondBootWithOverride(PortalContainer container) throws Exception { // RequestLifeCycle.begin(container); DataStorage dataStorage = (DataStorage) container.getComponentInstanceOfType(DataStorage.class); PortalConfig portal = dataStorage.getPortalConfig("classic"); Container layout = portal.getPortalLayout(); assertEquals(1, layout.getChildren().size()); Application<Portlet> layoutPortlet = (Application<Portlet>) layout.getChildren().get(0); assertEquals("site1/layout", dataStorage.getId(layoutPortlet.getState())); // Page home = dataStorage.getPage("portal::classic::home"); assertNotNull(home); assertEquals("site 1", home.getTitle()); Page page1 = dataStorage.getPage("portal::classic::page1"); assertNotNull(page1); assertEquals("site 1", page1.getTitle()); Page page2 = dataStorage.getPage("portal::classic::page2"); assertNotNull(page2); assertEquals("site 2", page2.getTitle()); Page dashboard1 = dataStorage.getPage("user::root::dashboard1"); assertNotNull(dashboard1); assertEquals("site 2", dashboard1.getTitle()); RequestLifeCycle.end(); }
/** * Find app instances by id. * * @param container the container * @param applicationId the application id * @return the application */ public static Application<?> findAppInstancesById(Container container, String applicationId) { ArrayList<ModelObject> chidren = container.getChildren(); if (chidren == null) return null; for (ModelObject object : chidren) { if (object instanceof Application) { Application<?> app = Application.class.cast(object); if (app.getId().equals(applicationId)) { application = app; } } else if (object instanceof Container) { Container child = Container.class.cast(object); findAppInstancesById(child, applicationId); } } return application; }
/** * Find app instances by container and name. * * @param container the container * @param applicationName the application name * @param results the results */ private static void findAppInstancesByContainerAndName( Container container, String applicationName, List<String> results) { ArrayList<ModelObject> chidren = container.getChildren(); if (chidren == null) return; for (ModelObject object : chidren) { if (object instanceof Application) { Application<?> application = Application.class.cast(object); if (application.getId().contains(applicationName)) { results.add(application.getId()); } } else if (object instanceof Container) { Container child = Container.class.cast(object); findAppInstancesByContainerAndName(child, applicationName, results); } } }
/** * Removed app instances in container by names. * * @param container the container * @param removingApplicationIds the removing application ids */ private static void removedAppInstancesInContainerByNames( Container container, List<String> removingApplicationIds) { ArrayList<ModelObject> childrenTmp = new ArrayList<ModelObject>(); ArrayList<ModelObject> chidren = container.getChildren(); if (chidren == null) return; for (ModelObject object : chidren) { if (object instanceof Application) { Application<?> application = Application.class.cast(object); if (!removingApplicationIds.contains(application.getId())) { childrenTmp.add(object); } } else if (object instanceof Container) { Container child = Container.class.cast(object); removedAppInstancesInContainerByNames(child, removingApplicationIds); childrenTmp.add(child); } } }
private static void buildUIContainer(UIContainer uiContainer, Object model, boolean dashboard) throws Exception { UIComponent uiComponent = null; WebuiRequestContext context = Util.getPortalRequestContext(); if (model instanceof SiteBody) { UISiteBody uiSiteBody = uiContainer.createUIComponent(context, UISiteBody.class, null, null); uiSiteBody.setStorageId(((SiteBody) model).getStorageId()); uiComponent = uiSiteBody; } else if (model instanceof PageBody) { UIPageBody uiPageBody = uiContainer.createUIComponent(context, UIPageBody.class, null, null); uiPageBody.setStorageId(((PageBody) model).getStorageId()); uiComponent = uiPageBody; } else if (model instanceof Application) { Application application = (Application) model; if (dashboard && application.getType() == ApplicationType.GADGET) { Application<Gadget> ga = (Application<Gadget>) application; UIGadget uiGadget = uiContainer.createUIComponent(context, UIGadget.class, null, null); uiGadget.setStorageId(application.getStorageId()); toUIGadget(uiGadget, ga); uiComponent = uiGadget; } else { UIPortlet uiPortlet = uiContainer.createUIComponent(context, UIPortlet.class, null, null); uiPortlet.setStorageId(application.getStorageId()); if (application.getStorageName() != null) { uiPortlet.setStorageName(application.getStorageName()); } toUIPortlet(uiPortlet, application); uiComponent = uiPortlet; } } else if (model instanceof Container) { Container container = (Container) model; UIComponentFactory<? extends UIContainer> factory = UIComponentFactory.getInstance(UIContainer.class); UIContainer uiTempContainer = factory.createUIComponent(container.getFactoryId(), context); if (uiTempContainer == null) { log.warn( "Can't find container factory for: {}. Default container is used", container.getFactoryId()); uiTempContainer = uiContainer.createUIComponent(context, UIContainer.class, null, null); } toUIContainer(uiTempContainer, (Container) model, dashboard); uiComponent = uiTempContainer; } uiContainer.addChild(uiComponent); }
private static void buildUIContainer(UIContainer uiContainer, Object model, boolean dashboard) throws Exception { UIComponent uiComponent = null; WebuiRequestContext context = Util.getPortalRequestContext(); if (model instanceof SiteBody) { UISiteBody uiSiteBody = uiContainer.createUIComponent(context, UISiteBody.class, null, null); uiSiteBody.setStorageId(((SiteBody) model).getStorageId()); uiComponent = uiSiteBody; } else if (model instanceof PageBody) { UIPageBody uiPageBody = uiContainer.createUIComponent(context, UIPageBody.class, null, null); uiPageBody.setStorageId(((PageBody) model).getStorageId()); uiComponent = uiPageBody; } else if (model instanceof Application) { Application application = (Application) model; if (dashboard && application.getType() == ApplicationType.GADGET) { Application<Gadget> ga = (Application<Gadget>) application; UIGadget uiGadget = uiContainer.createUIComponent(context, UIGadget.class, null, null); uiGadget.setStorageId(application.getStorageId()); toUIGadget(uiGadget, ga); uiComponent = uiGadget; } else { UIPortlet uiPortlet = uiContainer.createUIComponent(context, UIPortlet.class, null, null); uiPortlet.setStorageId(application.getStorageId()); if (application.getStorageName() != null) { uiPortlet.setStorageName(application.getStorageName()); } toUIPortlet(uiPortlet, application); uiComponent = uiPortlet; } } else if (model instanceof Container) { Container container = (Container) model; UIContainer uiTempContainer; if (UITabContainer.TAB_CONTAINER.equals(container.getFactoryId())) { uiTempContainer = uiContainer.createUIComponent(context, UITabContainer.class, null, null); } else if (UIColumnContainer.COLUMN_CONTAINER.equals(container.getFactoryId())) { uiTempContainer = uiContainer.createUIComponent(context, UIColumnContainer.class, null, null); } else { uiTempContainer = uiContainer.createUIComponent(context, UIContainer.class, null, null); } toUIContainer(uiTempContainer, (Container) model, dashboard); uiComponent = uiTempContainer; } uiContainer.addChild(uiComponent); }
/** * Fill the UI component with both information from the persistent model and some coming from the * portlet.xml defined by the JSR 286 specification */ private static <S> void toUIPortlet(UIPortlet<S, ?> uiPortlet, Application<S> model) { // PortletState<S> portletState = new PortletState<S>(model.getState(), model.getType()); /* * Fill UI component object with info from the XML file that persist portlet information */ uiPortlet.setWidth(model.getWidth()); uiPortlet.setHeight(model.getHeight()); uiPortlet.setState(portletState); uiPortlet.setTitle(model.getTitle()); uiPortlet.setIcon(model.getIcon()); uiPortlet.setDescription(model.getDescription()); uiPortlet.setShowInfoBar(model.getShowInfoBar()); uiPortlet.setShowWindowState(model.getShowApplicationState()); uiPortlet.setShowPortletMode(model.getShowApplicationMode()); uiPortlet.setProperties(model.getProperties()); uiPortlet.setTheme(model.getTheme()); if (model.getAccessPermissions() != null) uiPortlet.setAccessPermissions(model.getAccessPermissions()); uiPortlet.setModifiable(model.isModifiable()); Portlet portlet = uiPortlet.getProducedOfferedPortlet(); if (portlet == null || portlet.getInfo() == null) return; PortletInfo portletInfo = portlet.getInfo(); /* * Define which portlet modes the portlet supports and hence should be shown in the portlet info bar */ Set<ModeInfo> modes = portletInfo.getCapabilities().getModes(MediaType.create("text/html")); List<String> supportModes = new ArrayList<String>(); for (ModeInfo modeInfo : modes) { String modeName = modeInfo.getModeName().toLowerCase(); if ("config".equals(modeInfo.getModeName())) { supportModes.add(modeName); } else { supportModes.add(modeName); } } if (supportModes.size() > 1) supportModes.remove("view"); uiPortlet.setSupportModes(supportModes); }
public static void toUIGadget(UIGadget uiGadget, Application<Gadget> model) { uiGadget.setProperties(model.getProperties()); uiGadget.setState(model.getState()); }
private static <S> Application<S> toPortletModel(UIPortlet<S, ?> uiPortlet) { Application<S> model; PortletState<S> state = uiPortlet.getState(); ApplicationType<S> type = state.getApplicationType(); if (type == ApplicationType.PORTLET) { model = (Application<S>) Application.createPortletApplication(uiPortlet.getStorageId()); } else if (type == ApplicationType.GADGET) { model = (Application<S>) Application.createGadgetApplication(uiPortlet.getStorageId()); } else if (type == ApplicationType.WSRP_PORTLET) { model = (Application<S>) Application.createWSRPApplication(uiPortlet.getStorageId()); } else { throw new AssertionError(); } // model.setStorageName(uiPortlet.getStorageName()); model.setState(state.getApplicationState()); model.setTitle(uiPortlet.getTitle()); model.setWidth(uiPortlet.getWidth()); model.setHeight(uiPortlet.getHeight()); model.setDescription(uiPortlet.getDescription()); model.setShowInfoBar(uiPortlet.getShowInfoBar()); model.setShowApplicationState(uiPortlet.getShowWindowState()); model.setShowApplicationMode(uiPortlet.getShowPortletMode()); model.setDescription(uiPortlet.getDescription()); model.setIcon(uiPortlet.getIcon()); model.setProperties(uiPortlet.getProperties()); model.setTheme(uiPortlet.getTheme()); model.setAccessPermissions(uiPortlet.getAccessPermissions()); model.setModifiable(uiPortlet.isModifiable()); return model; }