Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Mar 21, 2023
2 parents 4ccd389 + d64854c commit 0b26e13
Show file tree
Hide file tree
Showing 5 changed files with 271 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,31 +202,43 @@ protected List<DashboardWidgetType> load() {
.end();

SimulationMetricReferenceType metricRef = m.getRef();
if (metricRef.getEventMarkRef() != null) {
ObjectReferenceType eventMarkRef = metricRef.getEventMarkRef();
String metricIdentifier = metricRef.getIdentifier();
if (eventMarkRef != null) {
PrismObject<MarkType> markObject =
WebModelServiceUtils.loadObject(metricRef.getEventMarkRef(), PageSimulationResult.this);
WebModelServiceUtils.loadObject(eventMarkRef, PageSimulationResult.this);
DisplayType display;
if (markObject != null) {
MarkType mark = markObject.asObjectable();
DisplayType display = mark.getDisplay();
display = mark.getDisplay();
if (display == null) {
display = new DisplayType();
display.setLabel(mark.getName());
}
dw.setDisplay(display);
dw.setDisplayOrder(mark.getDisplayOrder());
} else {
display = new DisplayType();
display.setLabel(new PolyStringType(WebComponentUtil.getName(eventMarkRef)));
}
} else if (metricRef.getIdentifier() != null) {

dw.setDisplay(display);
} else if (metricIdentifier != null) {
SimulationMetricDefinitionType def =
getSimulationResultManager().getMetricDefinition(metricRef.getIdentifier());
getSimulationResultManager().getMetricDefinition(metricIdentifier);
DisplayType display;
if (def != null) {
DisplayType display = def.getDisplay();
display = def.getDisplay();
if (display == null) {
display = new DisplayType();
display.setLabel(new PolyStringType(def.getIdentifier()));
}
dw.setDisplay(display);
dw.setDisplayOrder(def.getDisplayOrder());
} else {
display = new DisplayType();
display.setLabel(new PolyStringType(metricIdentifier));
}

dw.setDisplay(display);
} else {
// built-in -> ignored
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,13 @@ private ObjectFilter createObjectFilter(CollectionRefSpecificationType collectio
private void initLayout() {
add(AttributeModifier.prepend("class", "d-flex flex-column border rounded bg-white"));

Label title = new Label(ID_TITLE, () -> {
IModel<String> titleModel = () -> {
DisplayType display = getModelObject().getDisplay();
return display != null ? WebComponentUtil.getTranslatedPolyString(display.getLabel()) : null;
});
};

Label title = new Label(ID_TITLE, titleModel);
title.add(AttributeAppender.append("title", titleModel));
add(title);

BadgePanel trendBadge = new BadgePanel(ID_TREND_BADGE, () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.evolveum.midpoint.schema.RelationRegistry;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition;
import com.evolveum.midpoint.schema.processor.ResourceSchemaUtil;
import com.evolveum.midpoint.schema.util.FocusIdentityTypeUtil;
import com.evolveum.midpoint.schema.util.FocusTypeUtil;
import com.evolveum.midpoint.schema.util.WorkItemId;
Expand Down Expand Up @@ -1472,7 +1473,38 @@ interface TriggerCustomizer {
void customize(TriggerType trigger) throws SchemaException;
}

String describeResourceObjectSet(ResourceObjectSetType set) throws SchemaException, ExpressionEvaluationException, CommunicationException, SecurityViolationException, ConfigurationException, ObjectNotFoundException;
/**
* Returns longer version of human-readable description of the resource object set:
*
* . resource name
* . object type display name (if known)
* . object type ID (kind, intent)
* . flag whether we are using default type definition
* . object class
*
* Currently, object types are resolved and named using the
* {@link ResourceSchemaUtil#findDefinitionForBulkOperation(ResourceType, ShadowKindType, String, QName)} method
* that is used for import and reconciliation activities. Hence, the name should be quite precise in the context
* of these activities.
*/
String describeResourceObjectSetLong(ResourceObjectSetType set) throws SchemaException, ExpressionEvaluationException,
CommunicationException, SecurityViolationException, ConfigurationException, ObjectNotFoundException;

/**
* Short version of {@link #describeResourceObjectSetLong(ResourceObjectSetType)}:
*
* . only one of object type display name and type ID is shown;
* . object class is omitted when type is present
*/
String describeResourceObjectSetShort(ResourceObjectSetType set) throws SchemaException, ExpressionEvaluationException,
CommunicationException, SecurityViolationException, ConfigurationException, ObjectNotFoundException;

/** Synonym for {@link #describeResourceObjectSetShort(ResourceObjectSetType)}, mainly for compatibility reasons. */
default String describeResourceObjectSet(ResourceObjectSetType set) throws SchemaException, ExpressionEvaluationException,
CommunicationException, SecurityViolationException, ConfigurationException, ObjectNotFoundException {
return describeResourceObjectSetShort(set);
}


/**
* Selects specified values from all relevant identity data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;

import com.evolveum.midpoint.schema.processor.*;
import com.evolveum.midpoint.util.logging.LoggingUtils;

import com.google.common.base.Preconditions;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -86,10 +89,6 @@
import com.evolveum.midpoint.schema.constants.MidPointConstants;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.messaging.MessageWrapper;
import com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition;
import com.evolveum.midpoint.schema.processor.ResourceObjectDefinition;
import com.evolveum.midpoint.schema.processor.ResourceSchema;
import com.evolveum.midpoint.schema.processor.ResourceSchemaFactory;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.result.OperationResultStatus;
import com.evolveum.midpoint.schema.util.*;
Expand Down Expand Up @@ -234,6 +233,7 @@ public String getPlaintextAccountPasswordFromDelta(ObjectDelta<? extends ShadowT
}
}

@SuppressWarnings("rawtypes")
private void takePasswordsFromItemDelta(List<ProtectedStringType> passwords, ItemDelta itemDelta) {
if (itemDelta.isDelete()) {
return;
Expand Down Expand Up @@ -1311,8 +1311,7 @@ public ObjectDeltaType getResourceDelta(ModelContext<?> context, String resource
List<ObjectDelta<ShadowType>> deltas = new ArrayList<>();
for (Object modelProjectionContextObject : context.getProjectionContexts()) {
LensProjectionContext lensProjectionContext = (LensProjectionContext) modelProjectionContextObject;
if (lensProjectionContext.getKey() != null &&
resourceOid.equals(lensProjectionContext.getKey().getResourceOid())) {
if (resourceOid.equals(lensProjectionContext.getKey().getResourceOid())) {
deltas.add(lensProjectionContext.getSummaryDelta()); // union of primary and secondary deltas
}
}
Expand Down Expand Up @@ -2315,8 +2314,22 @@ public <T> T getExtensionOptionRealValue(String localName, Class<T> type) {
}

@Override
public String describeResourceObjectSet(ResourceObjectSetType set)
throws SchemaException, ExpressionEvaluationException, CommunicationException, SecurityViolationException, ConfigurationException, ObjectNotFoundException {
public String describeResourceObjectSetLong(ResourceObjectSetType set)
throws SchemaException, ExpressionEvaluationException, CommunicationException, SecurityViolationException,
ConfigurationException, ObjectNotFoundException {
return describeResourceObjectSet(set, true);
}

@Override
public String describeResourceObjectSetShort(ResourceObjectSetType set)
throws SchemaException, ExpressionEvaluationException, CommunicationException, SecurityViolationException,
ConfigurationException, ObjectNotFoundException {
return describeResourceObjectSet(set, false);
}

private String describeResourceObjectSet(ResourceObjectSetType set, boolean longVersion)
throws SchemaException, ExpressionEvaluationException, CommunicationException, SecurityViolationException,
ConfigurationException, ObjectNotFoundException {

if (set == null) {
return null;
Expand All @@ -2327,31 +2340,101 @@ public String describeResourceObjectSet(ResourceObjectSetType set)
return null;
}

ObjectType resource = resolveReferenceInternal(ref, true);
if (resource == null) {
ObjectType object = resolveReferenceInternal(ref, true);
if (!(object instanceof ResourceType)) {
return null;
}

ResourceType resource = (ResourceType) object;

StringBuilder sb = new StringBuilder();
sb.append(resource.getName().getOrig());

if (set.getObjectclass() != null) {
sb.append(" for ");
sb.append(set.getObjectclass().getLocalPart());
ShadowKindType kind = set.getKind();
String intent = set.getIntent();
QName objectclass = set.getObjectclass();

if (kind != null) {

sb.append(": ");

var definition = getResourceObjectDefinition(resource, kind, intent, objectclass);
ResourceObjectTypeIdentification typeIdentification = definition != null ? definition.getTypeIdentification() : null;

String typeDisplayName = definition != null ? definition.getDisplayName() : null;
if (typeDisplayName != null) {
sb.append(typeDisplayName);
if (longVersion) {
sb.append(" (");
sb.append(getTypeIdDescription(kind, intent, typeIdentification, true));
sb.append(")");
}
} else {
sb.append(getTypeIdDescription(kind, intent, typeIdentification, longVersion));
}
}

ShadowKindType kind = set.getKind();
if (kind != null || set.getIntent() != null) {
sb.append(" (");
sb.append(kind != null ? kind.value() : "");
sb.append("/");
sb.append(set.getIntent());
sb.append(")");
// Actually, kind/intent + object class should not be used both
if (objectclass != null && (longVersion || kind == null)) {
sb.append(" [").append(objectclass.getLocalPart()).append("]");
}

return sb.toString();
}

private @NotNull String getTypeIdDescription(
ShadowKindType origKind, String origIntent, ResourceObjectTypeIdentification resolvedTypeId, boolean longVersion) {
if (origIntent != null) {
return localizedTypeId(origKind, origIntent);
} else {
if (resolvedTypeId != null) {
if (longVersion) {
return localizationService.translate(
"TypeIdDescription.asTheDefaultIntent",
new Object[] { localizedTypeId(resolvedTypeId.getKind(), resolvedTypeId.getIntent()) },
localizationService.getDefaultLocale());
} else {
return localizedTypeId(resolvedTypeId.getKind(), resolvedTypeId.getIntent());
}
} else {
return localizationService.translate(
"TypeIdDescription.defaultIntentFor",
new Object[] { SingleLocalizableMessage.forEnum(origKind) },
localizationService.getDefaultLocale());
}
}
}

private String localizedTypeId(@NotNull ShadowKindType kind, @NotNull String intent) {
return localizationService.translate(
"TypeIdDescription.typeId",
new Object[] { SingleLocalizableMessage.forEnum(kind), intent },
localizationService.getDefaultLocale());
}

private ResourceObjectDefinition getResourceObjectDefinition(
ResourceType resource, ShadowKindType kind, String intent, QName objectclass) {
ResourceSchema completeSchema;
try {
completeSchema = Resource.of(resource).getCompleteSchema();
} catch (Exception e) {
LoggingUtils.logException(LOGGER, "Couldn't get schema for {}", e, resource);
return null;
}
if (completeSchema == null) {
return null;
}

try {
// This is the same method that is currently used when doing the processing in import/recon tasks.
return ResourceSchemaUtil.findDefinitionForBulkOperation(resource, kind, intent, objectclass);
} catch (Exception e) {
LoggingUtils.logException(LOGGER, "Couldn't get definition for {}/{}/{} in {}",
e, kind, intent, objectclass, resource);
return null;
}
}

@Override
public Collection<PrismValue> selectIdentityItemValues(
@Nullable Collection<FocusIdentityType> identities,
Expand Down

0 comments on commit 0b26e13

Please sign in to comment.