Skip to content

Commit

Permalink
Merge Layout Upgrade - Meeds-io/MIPs#131 (#886)
Browse files Browse the repository at this point in the history
  • Loading branch information
boubaker committed May 7, 2024
2 parents f73ab91 + 0f7ef00 commit 0db03cf
Show file tree
Hide file tree
Showing 17 changed files with 96 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public String getCssClass() {
if (cssClass != null) {
cssClasses.append(cssClass);
}
cssClasses.append(" d-flex flex-column d-md-grid");
cssClasses.append(" d-flex flex-column d-md-grid grid-cols");
cssClasses.append(" grid-cols-md-12");
cssClasses.append(" grid-cols-lg-12");
cssClasses.append(" grid-cols-xl-12");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public String getCssClass() {
if (cssClass != null) {
cssClasses.append(cssClass);
}
cssClasses.append(" d-flex flex-column d-md-grid");
cssClasses.append(" d-flex flex-column d-md-grid grid-cols grid-rows");
cssClasses.append(" grid-cols-md-").append(colsCount);
cssClasses.append(" grid-cols-lg-").append(colsCount);
cssClasses.append(" grid-cols-xl-").append(colsCount);
Expand Down
1 change: 1 addition & 0 deletions component/api/src/main/resources/binding.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
deserializer="org.exoplatform.portal.config.serialize.JibxArraySerialize.deserializePermissions" />
<collection field="children" ordered="false">
<structure map-as="org.exoplatform.portal.config.serialize.PortletApplication" usage="optional"/>
<structure map-as="org.exoplatform.portal.config.model.Container" usage="optional"/>
</collection>
</mapping>

Expand Down
5 changes: 4 additions & 1 deletion component/api/src/main/resources/gatein_objects_1_12.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,10 @@
<xs:complexType name="columnType">
<xs:sequence>
<xs:element name="access-permissions" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="portlet-application" type="portletApplicationType" minOccurs="0" maxOccurs="unbounded"/>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="portlet-application" type="portletApplicationType" minOccurs="1" maxOccurs="1" />
<xs:element name="container" type="containerType" minOccurs="1" maxOccurs="1" />
</xs:choice>
</xs:sequence>
<xs:attribute name="id" type="xs:string" />
<xs:attribute name="col-span">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void testParsePage() {
assertTrue("'TEST-columns-section-class' not found in:" + cssClasses, cssClasses.contains("TEST-columns-section-class"));

Container column = (Container) columnsSection.getChildren().get(0);
assertEquals(1, column.getChildren().size());
assertEquals(2, column.getChildren().size());
assertEquals("CellContainer", column.getTemplate());
assertNull(column.getBorderColor());
assertNotNull(column.getCssClass());
Expand All @@ -85,6 +85,8 @@ public void testParsePage() {
assertTrue("'brbl-0' not found", columnApplication.getCssClass().contains("brbl-0"));
assertTrue("'hidden-sm-and-down' not found", columnApplication.getCssClass().contains("hidden-sm-and-down"));

assertTrue(column.getChildren().get(1) instanceof Container);

Container gridSection = (Container) sectionsParent.getChildren().get(1);
assertEquals(3, gridSection.getChildren().size());
assertEquals("GridContainer", gridSection.getTemplate());
Expand Down
1 change: 1 addition & 0 deletions component/api/src/test/resources/page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<border-color>#CCAABB</border-color>
</css-style>
</portlet-application>
<container />
</column>
<!-- Minimum declaration of a column -->
<column col-span="3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,16 @@ public Collection<UserNode> getPortalSiteNavigations(String siteName, String por

public UserNode getPortalSiteRootNode(String siteName,String siteType, HttpServletRequest context) throws Exception {
HttpUserPortalContext userPortalContext = new HttpUserPortalContext(context);
UserPortalConfig userPortalConfig = getUserPortalConfig(siteName, context.getRemoteUser(), userPortalContext);
UserPortalConfig userPortalConfig = null;
String username = context.getRemoteUser();
if (StringUtils.equalsIgnoreCase(siteType, PortalConfig.PORTAL_TYPE)) {
userPortalConfig = getUserPortalConfig(siteName, username, userPortalContext);
} else {
PortalConfig defaultPortalConfig = getUserPortalSites().stream().findFirst().orElse(null);
if (defaultPortalConfig != null) {
userPortalConfig = getUserPortalConfig(defaultPortalConfig.getName(), username, userPortalContext);
}
}
if (userPortalConfig == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ public <T extends UIComponent> T removeChild(Class<T> clazz) {

@SuppressWarnings("unchecked")
public <T extends UIComponent> T getChildById(String id) {

if (children == null) {
List<UIComponent> subComponents = getChildren();
if (subComponents == null) {
return null;
}
for (UIComponent child : children) {
for (UIComponent child : subComponents) {
if (id.equals(child.getId())) {
return (T) child;
}
Expand All @@ -110,20 +110,22 @@ public <T extends UIComponent> T getChildById(String id) {

@SuppressWarnings("unchecked")
public <T extends UIComponent> T getChild(int idx) {
if (children == null) {
List<UIComponent> subComponents = getChildren();
if (subComponents == null) {
return null;
}
if (children.size() <= idx) {
if (subComponents.size() <= idx) {
return null;
}
return (T) children.get(idx);
return (T) subComponents.get(idx);
}

public <T extends UIComponent> T getChild(Class<T> clazz) {
if (children == null) {
List<UIComponent> subComponents = getChildren();
if (subComponents == null) {
return null;
}
for (UIComponent uichild : children) {
for (UIComponent uichild : subComponents) {
if (clazz.isInstance(uichild)) {
return clazz.cast(uichild);
}
Expand All @@ -135,15 +137,16 @@ public <T extends UIComponent> T getChild(Class<T> clazz) {

@SuppressWarnings("unchecked")
public <T extends UIComponent> T replaceChild(String targetChildId, UIComponent newComponent) throws Exception {
if (children == null) {
List<UIComponent> subComponents = getChildren();
if (subComponents == null) {
throw new Exception("Cannot find the child : " + targetChildId);
}
for (int i = 0; i < this.children.size(); i++) {
UIComponent child = this.children.get(i);
for (int i = 0; i < subComponents.size(); i++) {
UIComponent child = subComponents.get(i);
if (targetChildId.equals(child.getId())) {
child.setParent(null);
newComponent.setParent(this);
children.set(i, newComponent);
subComponents.set(i, newComponent);
return (T) child;
}
}
Expand Down Expand Up @@ -171,15 +174,14 @@ public <T extends UIComponent> T addChild(Class<T> type, String configId, String

@SuppressWarnings("unchecked")
public <T extends UIComponent> T findComponentById(String id) {
if (getId() != null) {
if (getId().equals(id)) {
return (T) this;
}
List<UIComponent> subComponents = getChildren();
if (getId() != null && getId().equals(id)) {
return (T) this;
}
if (children == null) {
if (subComponents == null) {
return null;
}
for (UIComponent uichild : children) {
for (UIComponent uichild : subComponents) {
UIComponent found = uichild.findComponentById(id);
if (found != null) {
return (T) found;
Expand All @@ -195,13 +197,14 @@ public <T extends UIComponent> T findComponentById(String id) {
*/

public <T extends UIComponent> T findFirstComponentOfType(Class<T> type) {
List<UIComponent> subComponents = getChildren();
if (type.isInstance(this)) {
return type.cast(this);
}
if (children == null) {
return null;
}
for (UIComponent uichild : children) {
for (UIComponent uichild : subComponents) {
T found = uichild.findFirstComponentOfType(type);
if (found != null) {
return found;
Expand All @@ -211,13 +214,14 @@ public <T extends UIComponent> T findFirstComponentOfType(Class<T> type) {
}

public <T> void findComponentOfType(List<T> list, Class<T> type) {
List<UIComponent> subComponents = getChildren();
if (type.isInstance(this) && !list.contains(this)) {
list.add(type.cast(this));
}
if (children == null) {
if (subComponents == null) {
return;
}
for (UIComponent uichild : children) {
for (UIComponent uichild : subComponents) {
uichild.findComponentOfType(list, type);
}
}
Expand Down Expand Up @@ -285,8 +289,7 @@ public void renderChildren() throws Exception {
}

public void renderChildren(WebuiRequestContext context) throws Exception {
List<UIComponent> list = getChildren();
for (UIComponent child : list) {
for (UIComponent child : getChildren()) {
if (child.isRendered()) {
child.processRender(context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
import java.util.List;

import org.exoplatform.portal.config.model.Application;
import org.exoplatform.portal.pom.spi.portlet.Portlet;

public interface AddOnService {

void addPlugin(AddOnPlugin plugin);

List<Application<?>> getApplications(String containerName);
List<Application<Portlet>> getApplications(String containerName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,38 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;

import org.apache.commons.lang3.StringUtils;

import org.exoplatform.portal.config.model.Application;
import org.exoplatform.portal.config.model.TransientApplicationState;
import org.exoplatform.portal.pom.data.ApplicationData;
import org.exoplatform.portal.pom.spi.portlet.Portlet;

public class AddOnServiceImpl implements AddOnService {

private List<ApplicationDecorator<?>> apps = new ArrayList<ApplicationDecorator<?>>();
private List<ApplicationDecorator<Portlet>> apps = new ArrayList<ApplicationDecorator<Portlet>>();

@Override
public List<Application<?>> getApplications(String containerName) {
List<Application<?>> apps = new LinkedList<Application<?>>();

for (ApplicationDecorator<?> app : this.apps) {
if (app.getContainerName().equals(containerName)) {
apps.add(app.getApp());
}
}
return apps;
public List<Application<Portlet>> getApplications(String containerName) {
return this.apps.stream()
.filter(app -> app.getContainerName().equals(containerName))
.map(ApplicationDecorator::getApp)
.toList();
}

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void addPlugin(AddOnPlugin plugin) {
for (Application<?> app : plugin.getApplications()) {
if (StringUtils.isBlank(app.getId())) {
app.setId(UUID.randomUUID().toString());
}
apps.add(new ApplicationDecorator(app, plugin.getPriority(), plugin.getContainerName()));
}
Collections.sort(apps, new Comparator<ApplicationDecorator<?>>() {
Collections.sort(apps, new Comparator<ApplicationDecorator<?>>() { // NOSONAR
@Override
public int compare(ApplicationDecorator<?> o1, ApplicationDecorator<?> o2) {
if (o1.getAppPriority() != o2.getAppPriority()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.Writer;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -62,7 +63,6 @@
import org.exoplatform.portal.mop.user.UserPortalContext;
import org.exoplatform.portal.url.PortalURLContext;
import org.exoplatform.portal.webui.page.UIPage;
import org.exoplatform.portal.webui.page.UIPageBody;
import org.exoplatform.portal.webui.portal.UIPortal;
import org.exoplatform.portal.webui.util.Util;
import org.exoplatform.portal.webui.workspace.UIPortalApplication;
Expand Down Expand Up @@ -90,6 +90,7 @@

import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;

import org.gatein.common.http.QueryStringParser;
import org.w3c.dom.Element;
Expand Down Expand Up @@ -323,6 +324,7 @@ public boolean isDraftPage() {
return draftPage.booleanValue();
}

@SneakyThrows
public UserNode getNavigationNode() {
if (userNode != null) {
return userNode;
Expand All @@ -331,7 +333,14 @@ public UserNode getNavigationNode() {
UserNavigation navigation = userPortal.getNavigation(siteKey);
if (navigation != null) {
Builder builder = UserNodeFilterConfig.builder().withReadCheck();
userNode = userPortal.resolvePath(navigation, builder.build(), nodePath_);
if (StringUtils.isBlank(nodePath_)) {
userNode = portalConfigService.getPortalSiteRootNode(siteKey.getName(), siteKey.getTypeName(), request_);
if (userNode != null) {
userNode = portalConfigService.getFirstAllowedPageNode(Collections.singletonList(userNode));
}
} else {
userNode = userPortal.resolvePath(navigation, builder.build(), nodePath_);
}
}
return userNode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public String getSkinId() {
}

public String getId() {
return storageId == null ? "UIPortlet-" + getStorageName() : storageId;
return storageId == null ? super.getId() : storageId;
}

public String getApplicationId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.exoplatform.portal.config.model.Application;
import org.exoplatform.portal.config.model.Container;
import org.exoplatform.portal.config.model.ModelObject;
import org.exoplatform.portal.pom.spi.portlet.Portlet;
import org.exoplatform.portal.webui.portal.UIPortalComponentActionListener.DeleteComponentActionListener;
import org.exoplatform.portal.webui.util.PortalDataMapper;
import org.exoplatform.portal.webui.util.Util;
Expand All @@ -50,11 +51,7 @@ public class UIAddOnContainer extends UIContainer {
public List<UIComponent> getChildren() {
if (!initialized) {
AddOnService addonService = getApplicationComponent(AddOnService.class);
List<Application<?>> apps = addonService.getApplications(this.getName());
for (int i = 0; i < apps.size(); i++) {
Application<?> app = apps.get(i);
app.setStorageName(this.getName() + "-" + i);
}
List<Application<Portlet>> apps = addonService.getApplications(this.getName());
Container model = new Container();
model.setChildren(new ArrayList<>(apps));
UIContainer tmp = new UIContainer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

import org.exoplatform.container.ExoContainer;
import org.exoplatform.portal.application.PortalRequestContext;
import org.exoplatform.portal.config.UserPortalConfigService;
import org.exoplatform.portal.config.model.Page;
import org.exoplatform.portal.mop.Visibility;
import org.exoplatform.portal.mop.page.PageContext;
import org.exoplatform.portal.mop.service.LayoutService;
import org.exoplatform.portal.mop.user.UserNode;
import org.exoplatform.portal.webui.portal.UIPortal;
import org.exoplatform.portal.webui.util.PortalDataMapper;
Expand Down Expand Up @@ -120,11 +120,11 @@ private UIPage getUIPage(UserNode pageNode, UIPortal uiPortal, WebuiRequestConte
PageContext pageContext = null;
String pageReference = null;
ExoContainer appContainer = context.getApplication().getApplicationServiceContainer();
UserPortalConfigService userPortalConfigService = appContainer.getComponentInstanceOfType(UserPortalConfigService.class);
LayoutService layoutService = appContainer.getComponentInstanceOfType(LayoutService.class);

if (pageNode != null && pageNode.getPageRef() != null) {
pageReference = pageNode.getPageRef().format();
pageContext = userPortalConfigService.getPage(pageNode.getPageRef());
pageContext = layoutService.getPageContext(pageNode.getPageRef());
}

// The page has been deleted
Expand All @@ -140,7 +140,7 @@ private UIPage getUIPage(UserNode pageNode, UIPortal uiPortal, WebuiRequestConte
if (uiPage == null) {
UIPageFactory clazz = UIPageFactory.getInstance(pageContext.getState().getFactoryId());
uiPage = clazz.createUIPage(context);
Page page = userPortalConfigService.getDataStorage().getPage(pageReference);
Page page = layoutService.getPage(pageReference);
pageContext.update(page);
PortalDataMapper.toUIPage(uiPage, page);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ private static <S> void toUIPortlet(UIPortlet<S, ?> uiPortlet, Application<S> mo
uiPortlet.setShowPortletMode(model.getShowApplicationMode());
uiPortlet.setProperties(model.getProperties());
uiPortlet.setTheme(model.getTheme());
uiPortlet.setId(model.getId());
if (model.getAccessPermissions() != null)
uiPortlet.setAccessPermissions(model.getAccessPermissions());
uiPortlet.setModifiable(model.isModifiable());
Expand Down

0 comments on commit 0db03cf

Please sign in to comment.