Skip to content

Commit

Permalink
Fix correlation properties display
Browse files Browse the repository at this point in the history
The "secondary" values for correlation properties were not shown
correctly. Also, the yellow color for partial match was not working.
Both are now fixed by restructuring the code - among others, the
already-computed match is reused in the GUI now.

This resolves MID-9411.
  • Loading branch information
mederly committed Jan 15, 2024
1 parent 780b2bd commit d79f5a0
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import com.evolveum.midpoint.model.api.correlation.CorrelationService;

import org.jetbrains.annotations.Nullable;
import com.evolveum.midpoint.util.DebugUtil;

import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.model.api.correlation.CorrelationCaseDescription;
Expand Down Expand Up @@ -74,6 +74,8 @@ class CorrelationContextDto implements Serializable {
private void load(CaseType aCase, PageBase pageBase, Task task, OperationResult result) throws CommonException {
ResourceObjectOwnerOptionsType ownerOptions = CorrelationCaseUtil.getOwnerOptions(aCase);
if (ownerOptions != null) {
// TODO Reconsider the necessity of this (note that everything is in candidate descriptions provided later,
// so we probably do not need the resolved candidates)
resolvePotentialOwners(ownerOptions, pageBase, task, result);
}
CorrelationCaseDescription<?> correlationCaseDescription =
Expand Down Expand Up @@ -108,6 +110,8 @@ private void resolve(ObjectReferenceType ref, String desc, PageBase pageBase, Ta

private PrismObject<?> loadObject(String oid, PageBase pageBase, Task task, OperationResult result) {
try {
// We do not need the identities container here, as the secondary values are obtained from
// the correlation case description.
return pageBase.getModelService()
.getObject(FocusType.class, oid, null, task, result);
} catch (Exception e) {
Expand All @@ -127,16 +131,25 @@ private void createCorrelationOptions(CaseType aCase, CorrelationCaseDescription
int suggestionNumber = 1;
for (ResourceObjectOwnerOptionType potentialOwner : CorrelationCaseUtil.getOwnerOptionsList(aCase)) {
OwnerOptionIdentifier identifier = OwnerOptionIdentifier.of(potentialOwner);
String optionIdentifierRaw = potentialOwner.getIdentifier(); // the same as identifier.getStringValue()
assert optionIdentifierRaw != null;
if (identifier.isNewOwner()) {
optionHeaders.add(0, TEXT_BEING_CORRELATED);
correlationOptions.add(0,
new CorrelationOptionDto(potentialOwner, context.getPreFocusRef()));
new CorrelationOptionDto.NewOwner(context.getPreFocusRef(), optionIdentifierRaw));
} else {
optionHeaders.add(String.format(TEXT_CANDIDATE, suggestionNumber));
CandidateDescription<?> candidate = candidates.get(identifier.getExistingOwnerId());
correlationOptions.add(
new CorrelationOptionDto(potentialOwner, candidate));
suggestionNumber++;
CandidateDescription<?> candidateDescription = candidates.get(identifier.getExistingOwnerId());
ObjectReferenceType candidateOwnerRef = potentialOwner.getCandidateOwnerRef(); // also in candidateDescription
if (candidateDescription != null && candidateOwnerRef != null) {
correlationOptions.add(
new CorrelationOptionDto.Candidate(candidateDescription, candidateOwnerRef, optionIdentifierRaw));
suggestionNumber++;
} else {
LOGGER.warn("No candidate or potentialOwner content for {}? In:\n{}\n{}",
identifier.getExistingOwnerId(),
DebugUtil.debugDump(candidates, 1), potentialOwner.debugDump(1));
}
}
}
}
Expand All @@ -151,22 +164,20 @@ private void createCorrelationPropertiesDefinitions(CaseType aCase, PageBase pag
.values());
}

@Nullable CorrelationOptionDto getNewOwnerOption() {
if (correlationOptions.isEmpty()) {
return null;
}
CorrelationOptionDto first = correlationOptions.get(0);
return first.isNewOwner() ? first : null;
}

/** Accessed via {@link #F_CORRELATION_OPTIONS}. */
@SuppressWarnings("unused")
public List<CorrelationOptionDto> getCorrelationOptions() {
return correlationOptions;
}

/** Accessed via {@link #F_OPTION_HEADERS}. */
@SuppressWarnings("unused")
public List<String> getOptionHeaders() {
return optionHeaders;
}

/** Accessed via {@link #F_CORRELATION_PROPERTIES}. */
@SuppressWarnings("unused")
public List<CorrelationCaseDescription.CorrelationProperty> getCorrelationProperties() {
return correlationProperties;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.StringResourceModel;

import com.evolveum.midpoint.gui.api.model.ReadOnlyModel;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.impl.page.admin.AbstractObjectMainPanel;
Expand Down Expand Up @@ -145,17 +144,20 @@ public void onClick(AjaxRequestTarget target) {
}
};

// Correlation candidate or "new owner" option.
CorrelationOptionDto optionDto = item.getModelObject();

actionButton.add(
new Label(ID_ACTION_LABEL,
item.getModelObject().isNewOwner() ? TEXT_CREATE_NEW : TEXT_CORRELATE));
optionDto.isNewOwner() ? TEXT_CREATE_NEW : TEXT_CORRELATE));

String outcome = correlationCase.getOutcome();
actionButton.add(new VisibleBehaviour(() -> outcome == null));
item.add(actionButton);

WebMarkupContainer iconType = new WebMarkupContainer(ID_OUTCOME_ICON);
iconType.setOutputMarkupId(true);
iconType.add(new VisibleBehaviour(() -> outcome != null && item.getModelObject().matches(outcome)));
iconType.add(new VisibleBehaviour(() -> outcome != null && optionDto.matches(outcome)));
item.add(iconType);
}
};
Expand All @@ -167,18 +169,16 @@ public void onClick(AjaxRequestTarget target) {
@Override
protected void populateItem(ListItem<CorrelationOptionDto> item) {
// A full-object reference to the candidate owner
ReadOnlyModel<ObjectReferenceType> referenceModel = new ReadOnlyModel<>(
() -> {
CorrelationOptionDto optionDto = item.getModelObject();
if (!optionDto.isNewOwner()) {
return ObjectTypeUtil.createObjectRefWithFullObject(
optionDto.getObject());
} else {
// GUI cannot currently open object that does not exist in the repository.
return null;
}
}
);
IModel<ObjectReferenceType> referenceModel = () -> {
CorrelationOptionDto optionDto = item.getModelObject();
if (!optionDto.isNewOwner()) {
return ObjectTypeUtil.createObjectRefWithFullObject(
optionDto.getObject());
} else {
// GUI cannot currently open object that does not exist in the repository.
return null;
}
};
item.add(
new LinkedReferencePanel<>(ID_NAME, referenceModel));
}
Expand Down Expand Up @@ -265,21 +265,31 @@ private ListView<CorrelationOptionDto> createColumnsForPropertyRow(
return new ListView<>(ID_COLUMNS, new PropertyModel<>(contextModel, CorrelationContextDto.F_CORRELATION_OPTIONS)) {
@Override
protected void populateItem(ListItem<CorrelationOptionDto> columnItem) {
CorrelationContextDto contextDto = contextModel.getObject();

// This is the column = option = the specific candidate (or "reference" object - the one that is being matched).
CorrelationOptionDto optionDto = columnItem.getModelObject();
CorrelationProperty correlationProperty = rowItem.getModelObject();

CorrelationPropertyValues valuesForOption = optionDto.getPropertyValues(correlationProperty);
Label label = new Label(ID_COLUMN, valuesForOption.format());
// This is the row = the correlation property in question (given name, family name, and so on).
CorrelationProperty correlationProperty = rowItem.getModelObject();

CorrelationOptionDto referenceOption = contextDto.getNewOwnerOption();
if (referenceOption != null && !optionDto.isNewOwner()) {
CorrelationPropertyValues referenceValues = referenceOption.getPropertyValues(correlationProperty);
Match match = referenceValues.match(valuesForOption);
label.add(
AttributeAppender.append("class", match.getCss()));
// Provide the values: either for a candidate or for the reference (object being matched).
CorrelationPropertyValues values = optionDto.getPropertyValues(correlationProperty);
Label valuesLabel = new Label(ID_COLUMN, values.format());

// Colorize the field
if (optionDto instanceof CorrelationOptionDto.Candidate candidate) {
MatchVisualizationStyle matchVisualizationStyle;
var propertyValuesDescription = candidate.getPropertyValuesDescription(correlationProperty);
if (propertyValuesDescription != null) {
matchVisualizationStyle = MatchVisualizationStyle.forMatch(propertyValuesDescription.getMatch());
} else {
matchVisualizationStyle = MatchVisualizationStyle.NOT_APPLICABLE;
}
valuesLabel.add(
AttributeAppender.append("class", matchVisualizationStyle.getCss()));
}
columnItem.add(label);

columnItem.add(valuesLabel);
}
};
}
Expand Down

0 comments on commit d79f5a0

Please sign in to comment.