-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MID-8842 ninja - user dashboard link processor + test
(cherry picked from commit c6690e5)
- Loading branch information
Showing
4 changed files
with
146 additions
and
5 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
...ain/java/com/evolveum/midpoint/schema/validator/processor/UserDashboardLinkProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package com.evolveum.midpoint.schema.validator.processor; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import com.evolveum.midpoint.prism.PrismObject; | ||
import com.evolveum.midpoint.prism.path.ItemPath; | ||
import com.evolveum.midpoint.schema.validator.UpgradeObjectProcessor; | ||
import com.evolveum.midpoint.schema.validator.UpgradePhase; | ||
import com.evolveum.midpoint.schema.validator.UpgradePriority; | ||
import com.evolveum.midpoint.schema.validator.UpgradeType; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.*; | ||
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
@SuppressWarnings("unused") | ||
public class UserDashboardLinkProcessor implements UpgradeObjectProcessor<ObjectType> { | ||
|
||
@Override | ||
public UpgradePriority getPriority() { | ||
return UpgradePriority.NECESSARY; | ||
} | ||
|
||
@Override | ||
public UpgradeType getType() { | ||
return UpgradeType.PREVIEW; | ||
} | ||
|
||
@Override | ||
public UpgradePhase getPhase() { | ||
return UpgradePhase.BEFORE; | ||
} | ||
|
||
@Override | ||
public boolean isApplicable(PrismObject<?> object, ItemPath path) { | ||
return matchParentTypeAndItemName(object, path, AdminGuiConfigurationType.class, AdminGuiConfigurationType.F_USER_DASHBOARD_LINK); | ||
} | ||
|
||
@Override | ||
public String upgradeDescription(PrismObject<ObjectType> object, ItemPath path) { | ||
return "Authorization of user dashboard links has to be configured manually via widget/visibility."; | ||
} | ||
|
||
@Override | ||
public boolean process(PrismObject<ObjectType> object, ItemPath path) { | ||
AdminGuiConfigurationType adminGuiConfig = getItemParent(object, path); | ||
List<RichHyperlinkType> links = adminGuiConfig.getUserDashboardLink(); | ||
|
||
List<HomePageType> homePages = adminGuiConfig.getHomePage(); | ||
HomePageType userHome = homePages.stream() | ||
.filter(hp -> UserType.COMPLEX_TYPE.equals(hp.getType())) | ||
.findFirst().orElse(null); | ||
|
||
if (userHome == null) { | ||
userHome = new HomePageType(); | ||
userHome.setType(UserType.COMPLEX_TYPE); | ||
userHome.setIdentifier("user"); | ||
homePages.add(userHome); | ||
} | ||
|
||
for (RichHyperlinkType link : links) { | ||
PreviewContainerPanelConfigurationType widget = new PreviewContainerPanelConfigurationType(); | ||
userHome.getWidget().add(widget); | ||
|
||
widget.setPanelType("linkWidget"); | ||
widget.setDocumentation(link.getDocumentation()); | ||
|
||
DisplayType display = new DisplayType(); | ||
widget.setDisplay(display); | ||
|
||
if (link.getLabel() != null) { | ||
display.setLabel(new PolyStringType(link.getLabel())); | ||
} | ||
if (link.getDescription() != null) { | ||
display.setHelp(new PolyStringType(link.getDescription())); | ||
} | ||
|
||
display.setIcon(link.getIcon()); | ||
|
||
if (link.getColor() != null) { | ||
IconType icon = display.getIcon(); | ||
if (icon == null) { | ||
icon = new IconType(); | ||
display.setIcon(icon); | ||
} | ||
|
||
icon.setCssClass(StringUtils.join(Arrays.asList( | ||
icon.getCssClass(), link.getColor()), " ")); | ||
} | ||
|
||
List<GuiActionType> actions = widget.getAction(); | ||
GuiActionType action = new GuiActionType(); | ||
action.setIdentifier("link"); | ||
action.setTarget(new RedirectionTargetType() | ||
.targetUrl(link.getTargetUrl())); | ||
actions.add(action); | ||
} | ||
|
||
links.clear(); | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters