Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
tchrapovic committed Aug 28, 2023
2 parents 89c529e + f946624 commit e385bd1
Show file tree
Hide file tree
Showing 4 changed files with 254 additions and 127 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!--
~ Copyright (c) 2023 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<wicket:panel>
<div wicket:id="headerPanel" class="d-flex align-items-center">
<div class="image">
<img wicket:id="photo" class="user-image img-circle elevation-2"/>
</div>
<div class="info">
<div class="text-lg" wicket:id="displayName"/>
<div class="text-md" wicket:id="archetypeLabel"/>
</div>
<a class="pull-right" wicket:id="expandButton">
<i wicket:id="arrowIcon"></i>
</a>
</div>
<div wicket:id="itemsPanel">
<label class="col-md-5" wicket:id="itemName"></label>
<div wicket:id="itemValue"/>
</div>
</wicket:panel>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
/*
* Copyright (c) 2023 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.gui.impl.page.lostusername;

import com.evolveum.midpoint.gui.api.GuiStyleConstants;
import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.util.GuiDisplayTypeUtil;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
import com.evolveum.midpoint.xml.ns._public.common.common_3.DisplayType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;

import com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityPolicyType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;

import org.apache.commons.io.IOUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.image.NonCachingImage;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.request.resource.AbstractResource;
import org.apache.wicket.request.resource.ByteArrayResource;

import java.io.IOException;
import java.io.Serial;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class IdentityDetailsPanel<F extends FocusType> extends BasePanel<F> {

@Serial private static final long serialVersionUID = 1L;

private static final String DOT_CLASS = IdentityDetailsPanel.class.getName() + ".";
private static final Trace LOGGER = TraceManager.getTrace(IdentityDetailsPanel.class);
private static final String OPERATION_GET_SECURITY_POLICY = DOT_CLASS + "getSecurityPolicy";

private static final String ID_HEADER_PANEL = "headerPanel";
private static final String ID_DISPLAY_NAME = "displayName";
private static final String ID_ARCHETYPE_LABEL = "archetypeLabel";
private static final String ID_PHOTO = "photo";
private static final String ID_EXPAND_BUTTON = "expandButton";
private static final String ID_ARROW_ICON = "arrowIcon";
private static final String ID_ITEMS_PANEL = "itemsPanel";
private static final String ID_ITEM_NAME = "itemName";
private static final String ID_ITEM_VALUE = "itemValue";

private boolean expanded;
private LoadableModel<List<ItemPathType>> itemsModel;
private SecurityPolicyType securityPolicy;

public IdentityDetailsPanel(String panelId, IModel<F> identityObject, SecurityPolicyType securityPolicy, boolean expanded) {
super(panelId, identityObject);
this.expanded = expanded;
this.securityPolicy = securityPolicy;
}

@Override
protected void onInitialize() {
super.onInitialize();
initModels();
initLayout();
}

private void initModels() {
itemsModel = new LoadableModel<>() {
@Serial private static final long serialVersionUID = 1L;

@Override
protected List<ItemPathType> load() {
return loadItemToDisplayList();
}
};
}

private List<ItemPathType> loadItemToDisplayList() {
var identityRecoveryConfig = securityPolicy.getIdentityRecovery();
List<ItemPathType> itemsToDisplay = identityRecoveryConfig.getItemToDisplay();
if (itemsToDisplay == null) {
itemsToDisplay = new ArrayList<>();
}
if (itemsToDisplay.size() == 0) {
itemsToDisplay.add(new ItemPathType(FocusType.F_NAME));
}
return itemsToDisplay;
}

private void initLayout() {
initHeaderPanel();
initDetailsPanel();
}

private void initHeaderPanel() {
WebMarkupContainer headerPanel = new WebMarkupContainer(ID_HEADER_PANEL);
headerPanel.setOutputMarkupId(true);
add(headerPanel);

NonCachingImage img = new NonCachingImage(ID_PHOTO, getImageResource());
headerPanel.add(img);

Label displayNameLabel = new Label(ID_DISPLAY_NAME, getDisplayNameModel());
headerPanel.add(displayNameLabel);

Label archetypeLabel = new Label(ID_ARCHETYPE_LABEL, getArchetypeModel());
headerPanel.add(archetypeLabel);

AjaxButton arrowButton = new AjaxButton(ID_EXPAND_BUTTON) {
@Override
public void onClick(AjaxRequestTarget ajaxRequestTarget) {
expanded = !expanded;
ajaxRequestTarget.add(IdentityDetailsPanel.this);
}
};
arrowButton.setOutputMarkupId(true);
headerPanel.add(arrowButton);

WebMarkupContainer icon = new WebMarkupContainer(ID_ARROW_ICON);
icon.add(AttributeAppender.append("class", this::getArrowIconCss));
arrowButton.add(icon);
}

private void initDetailsPanel() {
ListView<ItemPathType> itemsPanel = new ListView<>(ID_ITEMS_PANEL, itemsModel) {

@Serial private static final long serialVersionUID = 1L;

@Override
protected void populateItem(ListItem<ItemPathType> attributeItem) {
Label itemName = new Label(ID_ITEM_NAME, resolveItemName(attributeItem.getModelObject()));
itemName.setOutputMarkupId(true);
attributeItem.add(itemName);

Label itemValue = new Label(ID_ITEM_VALUE, resolveItemValue(attributeItem.getModelObject()));
itemValue.setOutputMarkupId(true);
attributeItem.add(itemValue);
}
};
itemsPanel.setOutputMarkupId(true);
itemsPanel.add(new VisibleBehaviour(() -> expanded));
add(itemsPanel);
}

private AbstractResource getImageResource() {
byte[] photo = null;
if (getModelObject() instanceof UserType user) {
photo = user.getJpegPhoto();
if (photo == null) {
URL defaultImage = this.getClass().getClassLoader().getResource("static/img/placeholder.png");
if (defaultImage == null) {
return null;
}
try {
photo = IOUtils.toByteArray(defaultImage);
} catch (IOException e) {
return null;
}
}
}
return new ByteArrayResource("image/jpeg", photo);
}

private IModel<String> getDisplayNameModel() {
return () -> WebComponentUtil.getDisplayNameOrName(getModelObject().asPrismObject());
}

private IModel<String> getArchetypeModel() {
return () -> {
DisplayType archetypeDisplay =
GuiDisplayTypeUtil.getArchetypePolicyDisplayType(getModelObject().asPrismObject(), getParentPage());
return GuiDisplayTypeUtil.getTranslatedLabel(archetypeDisplay);
};
}

private String getArrowIconCss() {
return expanded ? GuiStyleConstants.CLASS_ICON_COLLAPSE : GuiStyleConstants.CLASS_ICON_EXPAND;
}

private IModel<String> resolveItemName(ItemPathType itemPath) {
return () -> {
ItemDefinition<?> def = getModelObject().asPrismObject().getDefinition().findItemDefinition(itemPath.getItemPath());
return WebComponentUtil.getItemDefinitionDisplayNameOrName(def);
};
}

private IModel<String> resolveItemValue(ItemPathType itemPath) {
return () -> {
var item = getModelObject().asPrismObject().findItem(itemPath.getItemPath());
var value = item != null ? item.getRealValue() : null;
return value == null ? "" : value.toString();
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,8 @@
<html xmlns:wicket="http://wicket.apache.org">
<body>
<wicket:extend>
<div wicket:id="recoveredIdentities">
<div wicket:id="loginNamePanel" class="user-panel info-box my-3 pb-2 d-flex justify-content-start align-items-center">
<div class="image">
<img wicket:id="photo" class="user-image img-circle elevation-2"/>
</div>
<div class="info">
<div class="text-lg" wicket:id="loginName"/>
</div>
</div>
<wicket:enclosure child="configuredItemsPanel">
<div class="user-panel info-box d-flex flex-column justify-content-start mt-5 col-12">
<div wicket:id="configuredItemsPanel" class="d-flex justify-content-start">
<label class="col-md-5" wicket:id="itemName"></label>
<div wicket:id="itemValue"/>
</div>
</div>
</wicket:enclosure>
<div wicket:id="recoveredIdentities" class="user-panel info-box my-3 pb-2 ">
<div wicket:id="detailsPanel" />
</div>
<div class="d-flex justify-content-end mt-2">
<a wicket:id="registrationLink" class="text-center login-panel-control">
Expand Down

0 comments on commit e385bd1

Please sign in to comment.