Skip to content

Commit

Permalink
MID-8865: fixed name of shadow in result simulation table
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Oct 2, 2023
1 parent b5df130 commit 5575756
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,11 @@ protected Search<SimulationResultProcessedObjectType> load() {
@Override
protected Item<IColumn<SelectableBean<SimulationResultProcessedObjectType>, String>> newCellItem(String id, int index, IModel<IColumn<SelectableBean<SimulationResultProcessedObjectType>, String>> model) {
Item<IColumn<SelectableBean<SimulationResultProcessedObjectType>, String>> item = super.newCellItem(id, index, model);
if(index == 1) {
if (index == 1) {
item.add(AttributeAppender.append("style", "word-break:break-all"));
}
item.add(AttributeAppender.append("class", "align-middle"));


return item;
}

Expand Down Expand Up @@ -471,9 +470,17 @@ private void onBackPerformed() {
}

private IModel<String> createTitleModel() {
return () ->
WebComponentUtil.getOrigStringFromPoly(objectModel.getObject().getName())
+ " (" + WebComponentUtil.getDisplayNameOrName(resultModel.getObject().asPrismObject()) + ")";
return () -> {
String name = WebComponentUtil.getOrigStringFromPoly(objectModel.getObject().getName());

if (StringUtils.isEmpty(name)) {
SimulationResultProcessedObjectType object = objectModel.getObject();
ProcessedObject<?> processedObject = SimulationsGuiUtil.parseProcessedObject(object, PageSimulationResultObject.this);
name = SimulationsGuiUtil.getShadowNameFromAttribute(processedObject);
}

return name + " (" + WebComponentUtil.getDisplayNameOrName(resultModel.getObject().asPrismObject()) + ")";
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
import com.evolveum.midpoint.web.component.util.SelectableBean;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.jetbrains.annotations.Nullable;

/**
* Created by Viliam Repan (lazyman).
*/
Expand Down Expand Up @@ -175,7 +177,7 @@ public static VisualizationDto createVisualizationDto(Visualization visualizatio
}

public static String getProcessedObjectName(ProcessedObject<?> object, PageBase page) {
if (object == null || object.getName() == null) {
if (object == null) {
return page.getString("ProcessedObjectsPanel.unnamed");
}

Expand Down Expand Up @@ -216,6 +218,33 @@ public static String getProcessedObjectName(ProcessedObject<?> object, PageBase
return name + " (" + displayName + ")";
}

@Nullable
public static String getShadowNameFromAttribute(ProcessedObject<?> object) {

if (object == null) {
return null;
}

ObjectType obj = ObjectProcessingStateType.DELETED.equals(object.getState()) ? object.getBefore() : object.getAfter();
if (obj == null) {
return null;
}

if (!(obj instanceof ShadowType)) {
return null;
}

String name = null;
try {
ResourceAttribute<?> namingAttribute = ShadowUtil.getNamingAttribute((ShadowType) obj);
Object realName = namingAttribute != null ? namingAttribute.getRealValue() : null;
name = realName != null ? realName.toString() : null;
} catch (SystemException e) {
LOGGER.debug("Couldn't create processed shadow name", e);
}
return name;
}

private static String getProcessedShadowName(ShadowType shadow, PageBase page) {
ShadowKindType kind = shadow.getKind() != null ? shadow.getKind() : ShadowKindType.UNKNOWN;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;

import org.jetbrains.annotations.Nullable;

/**
* Created by Viliam Repan (lazyman).
*/
public interface VisualizationDescriptionHandler {

boolean match(VisualizationImpl visualization, VisualizationImpl parentVisualization);
boolean match(VisualizationImpl visualization, @Nullable VisualizationImpl parentVisualization);

void apply(VisualizationImpl visualization, VisualizationImpl parentVisualization, Task task, OperationResult result);
void apply(VisualizationImpl visualization, @Nullable VisualizationImpl parentVisualization, Task task, OperationResult result);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@

import java.util.*;

import com.evolveum.midpoint.schema.processor.ResourceAttribute;
import com.evolveum.midpoint.schema.util.ShadowUtil;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -104,7 +108,7 @@ private VisualizationImpl visualize(PrismObject<? extends ObjectType> object, Vi
visualization.setSourceDelta(null);
visualizeItems(visualization, object.getValue().getItems(), false, context, task, result);

evaluateDescriptionHandlers(visualization, visualization, task, result);
evaluateDescriptionHandlers(visualization, owner, task, result);

return visualization;
}
Expand Down Expand Up @@ -282,7 +286,7 @@ private VisualizationImpl visualizeDelta(ObjectDelta<? extends ObjectType> objec
throw new IllegalStateException("Object delta that is neither ADD, nor MODIFY nor DELETE: " + objectDelta);
}

evaluateDescriptionHandlers(visualization, visualization, task, result);
evaluateDescriptionHandlers(visualization, null, task, result);

return visualization;
}
Expand Down Expand Up @@ -514,7 +518,7 @@ private <C extends Containerable> void visualizeContainerDeltaValue(PrismContain

parentVisualization.addPartialVisualization(visualization);

evaluateDescriptionHandlers(visualization, visualization, task, result);
evaluateDescriptionHandlers(visualization, parentVisualization, task, result);
}

private void evaluateDescriptionHandlers(
Expand Down Expand Up @@ -948,6 +952,14 @@ private NameImpl createVisualizationName(PrismObject<? extends ObjectType> objec
name.setDisplayName(getOrig(((UserType) objectType).getFullName()));
} else if (objectType instanceof AbstractRoleType) {
name.setDisplayName(getOrig(((AbstractRoleType) objectType).getDisplayName()));
} else if (objectType instanceof ShadowType shadow) {
if (object.getName() == null) {
ResourceAttribute<?> namingAttribute = ShadowUtil.getNamingAttribute(shadow);
Object realName = namingAttribute != null ? namingAttribute.getRealValue() : null;
if (realName != null) {
name.setDisplayName(realName.toString());
}
}
}
return name;
}
Expand Down

0 comments on commit 5575756

Please sign in to comment.