Skip to content

Commit

Permalink
userDashboard cleanup in compiledGuiProfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Kateryna Honchar committed Jun 7, 2023
1 parent 7969742 commit 1e3a662
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,14 @@ public enum PredefinedDashboardWidgetId {
PREVIEW_WIDGETS("previewWidgets"),
MY_ACCOUNTS("myAccounts");

private final QName qname;
private final String uri;
private final String identifier;

PredefinedDashboardWidgetId(String localPart) {
this.qname = new QName(ComponentConstants.NS_DASHBOARD_WIDGET, localPart);
this.uri = QNameUtil.qNameToUri(qname);
PredefinedDashboardWidgetId(String identifier) {
this.identifier = identifier;
}

public QName getQname() {
return qname;
}

public String getUri() {
return uri;
public String getIdentifier() {
return identifier;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.evolveum.midpoint.gui.impl.page.self.dashboard;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -98,7 +99,9 @@ private void initLayout() {
}

private void initStatisticWidgets(Form mainForm) {
ListView<PreviewContainerPanelConfigurationType> statisticWidgetsPanel = new ListView<>(ID_STATISTIC_WIDGETS_PANEL, this::getStatisticWidgetList) {
List<PreviewContainerPanelConfigurationType> statisticWidgets = getStatisticWidgetList();
ListView<PreviewContainerPanelConfigurationType> statisticWidgetsPanel = new ListView<>(ID_STATISTIC_WIDGETS_PANEL,
statisticWidgets) {

private static final long serialVersionUID = 1L;

Expand All @@ -110,16 +113,14 @@ protected void populateItem(ListItem<PreviewContainerPanelConfigurationType> ite
}
};
statisticWidgetsPanel.setOutputMarkupId(true);
statisticWidgetsPanel.add(new VisibleBehaviour(() -> {
UserInterfaceElementVisibilityType visibility = getComponentVisibility(PredefinedDashboardWidgetId.SHORTCUTS);
return WebComponentUtil.getElementVisibility(visibility);
}));
statisticWidgetsPanel.add(new VisibleBehaviour(() -> CollectionUtils.isNotEmpty(statisticWidgets)));
mainForm.add(statisticWidgetsPanel);

}

private void initPreviewWidgets(Form mainForm) {
ListView<PreviewContainerPanelConfigurationType> viewWidgetsPanel = new ListView<>(ID_OBJECT_COLLECTION_VIEW_WIDGETS_PANEL, this::getNonStatisticWidgetList) {
List<PreviewContainerPanelConfigurationType> previewWidgets = getNonStatisticWidgetList();
ListView<PreviewContainerPanelConfigurationType> viewWidgetsPanel = new ListView<>(ID_OBJECT_COLLECTION_VIEW_WIDGETS_PANEL, previewWidgets) {

@Override
protected void populateItem(ListItem<PreviewContainerPanelConfigurationType> item) {
Expand All @@ -130,10 +131,7 @@ protected void populateItem(ListItem<PreviewContainerPanelConfigurationType> ite
}
};
viewWidgetsPanel.setOutputMarkupId(true);
viewWidgetsPanel.add(new VisibleBehaviour(() -> {
UserInterfaceElementVisibilityType visibility = getComponentVisibility(PredefinedDashboardWidgetId.PREVIEW_WIDGETS);
return getCompiledGuiProfile().getHomePage() != null && WebComponentUtil.getElementVisibility(visibility);
}));
viewWidgetsPanel.add(new VisibleBehaviour(() -> CollectionUtils.isNotEmpty(previewWidgets)));
mainForm.add(viewWidgetsPanel);
}

Expand All @@ -160,9 +158,10 @@ private List<PreviewContainerPanelConfigurationType> getNonStatisticWidgetList()
HomePageType homePageType = getCompiledGuiProfile().getHomePage();
List<PreviewContainerPanelConfigurationType> allWidgetList = homePageType != null ? homePageType.getWidget() : null;
if (allWidgetList == null) {
return null;
return Collections.emptyList();
}
return allWidgetList.stream().filter(w -> !LINK_WIDGET_IDENTIFIER.equals(w.getPanelType())).collect(Collectors.toList());
return allWidgetList.stream().filter(w -> w.getPanelType() != null &&
!LINK_WIDGET_IDENTIFIER.equals(w.getPanelType())).collect(Collectors.toList());
}

private LoadableDetachableModel<PrismObject<UserType>> createSelfModel() {
Expand Down Expand Up @@ -215,24 +214,23 @@ public List<? extends ContainerPanelConfigurationType> getPanelConfigurations()

private UserInterfaceElementVisibilityType getComponentVisibility(PredefinedDashboardWidgetId componentId) {
CompiledGuiProfile compiledGuiProfile = getCompiledGuiProfile();
if (compiledGuiProfile.getUserDashboard() == null) {
if (compiledGuiProfile.getHomePage() == null) {
return UserInterfaceElementVisibilityType.AUTOMATIC;
}
List<DashboardWidgetType> widgetsList = compiledGuiProfile.getUserDashboard().getWidget();
List<PreviewContainerPanelConfigurationType> widgetsList = compiledGuiProfile.getHomePage().getWidget();
if (CollectionUtils.isEmpty(widgetsList)) {
return UserInterfaceElementVisibilityType.VACANT;
}
HomePageType homePage = compiledGuiProfile.getHomePage();
List<PreviewContainerPanelConfigurationType> containerPanelWidgets = homePage == null ? null : compiledGuiProfile.getHomePage().getWidget();
if (CollectionUtils.isEmpty(containerPanelWidgets)) {
String widgetIdentifier = componentId.getIdentifier();
PreviewContainerPanelConfigurationType widget = widgetsList
.stream()
.filter(w -> widgetIdentifier.equals(w.getIdentifier()))
.findFirst()
.orElse(null);
if (widget == null) {
return UserInterfaceElementVisibilityType.VACANT;
}
DashboardWidgetType widget = compiledGuiProfile.findUserDashboardWidget(componentId.getUri());
if (widget == null || widget.getVisibility() == null) {
return UserInterfaceElementVisibilityType.HIDDEN;
} else {
return widget.getVisibility();
}
return widget.getVisibility();
}

private List<RichHyperlinkType> loadLinksList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public class CompiledGuiProfile implements DebugDumpable, Serializable {
private List<CompiledObjectCollectionView> objectCollectionViews = new ArrayList<>();
private List<CompiledShadowCollectionView> shadowCollectionViews = new ArrayList<>();
private CompiledObjectCollectionView defaultObjectCollectionView = null;
private DashboardLayoutType userDashboard;
private List<CompiledDashboardType> configurableDashboards = new ArrayList<>();
private GuiExportSettingsType defaultExportSettings;
private GuiObjectDetailsSetType objectDetails;
Expand Down Expand Up @@ -131,19 +130,6 @@ public List<RichHyperlinkType> getUserDashboardLink() {
return userDashboardLink;
}

/**
* Very likely to change in the future (for "flexible dashboards" feature).
*/
@Experimental
public DashboardLayoutType getUserDashboard() {
return userDashboard;
}

@Experimental
public void setUserDashboard(DashboardLayoutType userDashboard) {
this.userDashboard = userDashboard;
}

public List<CompiledDashboardType> getConfigurableDashboards() {
return configurableDashboards;
}
Expand Down Expand Up @@ -481,14 +467,6 @@ public static boolean isVisible(UserInterfaceElementVisibilityType visibility, B
return false;
}

@Experimental
public DashboardWidgetType findUserDashboardWidget(String widgetIdentifier) {
if (userDashboard == null) {
return null;
}
return findFeature(userDashboard.getWidget(), widgetIdentifier);
}

// TODO: later: information about menu structure

public AccessRequestType getAccessRequest() {
Expand All @@ -510,7 +488,7 @@ public String debugDump(int indent) {
DebugUtil.debugDumpWithLabelLn(sb, "userDashboardLink", userDashboardLink, indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "objectCollectionViews", objectCollectionViews, indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "defaultObjectCollectionView", defaultObjectCollectionView, indent + 1);
DebugUtil.debugDumpWithLabelToStringLn(sb, "userDashboard", userDashboard, indent + 1);
DebugUtil.debugDumpWithLabelToStringLn(sb, "homePage", homePage, indent + 1);
DebugUtil.debugDumpWithLabelToStringLn(sb, "defaultExportSettings", defaultExportSettings, indent + 1);
DebugUtil.debugDumpWithLabelToStringLn(sb, "objectDetails", objectDetails, indent + 1);
DebugUtil.debugDumpWithLabelToStringLn(sb, "feedbackMessagesHook", feedbackMessagesHook, indent + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,21 +635,6 @@ private String resolveReferenceIfNeeded(ObjectReferenceType reference, Operation
return reference.getOid();
}

private void mergeWidget(CompiledGuiProfile composite, DashboardWidgetType newWidget) {
String newWidgetIdentifier = newWidget.getIdentifier();
DashboardWidgetType compositeWidget = composite.findUserDashboardWidget(newWidgetIdentifier);
if (compositeWidget == null) {
composite.getUserDashboard().getWidget().add(newWidget.clone());
} else {
mergeWidget(compositeWidget, newWidget);
}
}

private void mergeWidget(DashboardWidgetType compositeWidget, DashboardWidgetType newWidget) {
mergeFeature(compositeWidget, newWidget, UserInterfaceElementVisibilityType.VACANT);
// merge other widget properties (in the future)
}

private void mergeFeature(CompiledGuiProfile composite, UserInterfaceFeatureType newFeature) {
String newIdentifier = newFeature.getIdentifier();
UserInterfaceFeatureType compositeFeature = composite.findFeature(newIdentifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@

import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertTrue;

import com.evolveum.midpoint.xml.ns._public.common.common_3.HomePageType;

import com.evolveum.midpoint.xml.ns._public.common.common_3.PreviewContainerPanelConfigurationType;

import org.testng.AssertJUnit;

import com.evolveum.midpoint.model.api.authentication.CompiledGuiProfile;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
import com.evolveum.midpoint.test.asserter.AbstractAsserter;

import java.util.List;

/**
* @author semancik
*
Expand Down Expand Up @@ -49,18 +54,24 @@ public CompiledGuiProfileAsserter<RA> assertUserDashboardLinks(int expectedLinks
return this;
}

public CompiledGuiProfileAsserter<RA> assertUserDashboardWidgets(int expectedWidgetws) {
if ( compiledGuiProfile.getUserDashboard() == null) {
if (expectedWidgetws != 0) {
fail("Wrong number of widgets in user dashboard admin GUI configuration, expected "
+ expectedWidgetws + " but there was none");
}
} else {
assertEquals("Wrong number of user dashboard widgets in " + desc(), expectedWidgetws, getCompiledGuiProfile().getUserDashboard().getWidget().size());
}
public CompiledGuiProfileAsserter<RA> assertUserDashboardWidgets(int expectedWidgets) {
int userDashboardWidgetsCount = countUserDashboardWidgets();
assertEquals("Wrong number of user dashboard widgets in " + desc(), expectedWidgets, userDashboardWidgetsCount);
return this;
}

public int countUserDashboardWidgets() {
HomePageType homePage = compiledGuiProfile.getHomePage();
if (homePage == null) {
return 0;
}
List<PreviewContainerPanelConfigurationType> widgets = homePage.getWidget();
if (widgets == null) {
return 0;
}
return widgets.size();
}

public CompiledGuiProfileAsserter<RA> assertObjectCollectionViews(int expectedViews) {
assertEquals("Wrong number of object collection views in " + desc(), expectedViews, getCompiledGuiProfile().getObjectCollectionViews().size());
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@
<adminGuiConfiguration>
<homePage>
<type>UserType</type>
<widget>
<identifier>search</identifier>
</widget>
<widget>
<identifier>myAccesses</identifier>
<display>
Expand Down

0 comments on commit 1e3a662

Please sign in to comment.