Skip to content

Commit

Permalink
Do minor tweaks to correlation cases viewing
Browse files Browse the repository at this point in the history
1) Added dummy "new account" option (not so great idea).
2) Closing work items along with the correlation case.
3) Comparing attributes in case-insensitive way - because of (1) above.
  • Loading branch information
mederly committed Jan 17, 2022
1 parent 80188ca commit 061e5d4
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
package com.evolveum.midpoint.gui.impl.page.admin.cases.component;

import com.evolveum.midpoint.prism.Item;
import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.IdMatchCorrelationPotentialMatchType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAttributesType;
Expand All @@ -34,7 +37,7 @@ public void setOrigin(boolean origin) {
}

public Serializable getAttributeValue(ItemPath path) {
Item pItem = shadowAttributesType.asPrismContainerValue().findItem(path);
Item pItem = findMatchingItem(path);
Serializable value = pItem == null ? null : (Serializable) pItem.getRealValue();
// String realValue;
if (value instanceof RawType) {
Expand All @@ -47,6 +50,25 @@ public Serializable getAttributeValue(ItemPath path) {
return value;
}

private Item findMatchingItem(ItemPath path) {
Item exactMatch = shadowAttributesType.asPrismContainerValue().findItem(path);
if (exactMatch != null) {
return exactMatch;
}
ItemName name = path.asSingleName();
if (name == null) {
// Not bothering with the general case; we don't have nested attributes anyway
return null;
}

for (Item<?, ?> item : ((PrismContainerValue<?>) shadowAttributesType.asPrismContainerValue()).getItems()) {
if (QNameUtil.match(name, item.getElementName(), true)) {
return item;
}
}
return null;
}

public ShadowAttributesType getShadowAttributesType() {
return shadowAttributesType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,41 @@

package com.evolveum.midpoint.model.impl.correlator;

import static com.evolveum.midpoint.schema.util.ObjectTypeUtil.*;
import static com.evolveum.midpoint.schema.util.ObjectTypeUtil.createObjectRef;
import static com.evolveum.midpoint.schema.util.ObjectTypeUtil.createObjectRefWithFullObject;
import static com.evolveum.midpoint.util.MiscUtil.argCheck;

import java.util.List;

import com.evolveum.midpoint.common.Clock;
import com.evolveum.midpoint.model.api.correlator.Correlator;
import com.evolveum.midpoint.model.api.correlator.CorrelatorFactoryRegistry;
import com.evolveum.midpoint.model.impl.ModelBeans;
import com.evolveum.midpoint.prism.query.builder.S_AtomicFilterExit;
import com.evolveum.midpoint.schema.constants.SchemaConstants;

import com.evolveum.midpoint.schema.util.WorkItemId;

import com.evolveum.midpoint.security.api.SecurityUtil;
import com.evolveum.midpoint.task.api.Task;

import com.evolveum.midpoint.util.exception.*;
import javax.xml.datatype.XMLGregorianCalendar;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.evolveum.midpoint.common.Clock;
import com.evolveum.midpoint.model.api.correlator.Correlator;
import com.evolveum.midpoint.model.api.correlator.CorrelatorFactoryRegistry;
import com.evolveum.midpoint.model.impl.ModelBeans;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.prism.delta.builder.S_ItemEntry;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.query.builder.S_AtomicFilterExit;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.WorkItemId;
import com.evolveum.midpoint.security.api.SecurityUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import javax.xml.datatype.XMLGregorianCalendar;

/**
* Manages correlation cases.
*/
Expand Down Expand Up @@ -201,11 +198,18 @@ public void closeCaseIfExists(
CaseType aCase = findCorrelationCase(resourceObject, true, result);
if (aCase != null) {
LOGGER.debug("Marking correlation case as closed: {}", aCase);
List<ItemDelta<?, ?>> itemDeltas = prismContext.deltaFor(CaseType.class)
S_ItemEntry builder = prismContext.deltaFor(CaseType.class)
.item(CaseType.F_STATE)
.replace(SchemaConstants.CASE_STATE_CLOSED)
.asItemDeltas();
modifyCase(aCase, itemDeltas, result);
.replace(SchemaConstants.CASE_STATE_CLOSED);
XMLGregorianCalendar now = clock.currentTimeXMLGregorianCalendar();
for (CaseWorkItemType workItem : aCase.getWorkItem()) {
if (workItem.getCloseTimestamp() == null) {
builder = builder
.item(CaseType.F_WORK_ITEM, workItem.getId(), CaseWorkItemType.F_CLOSE_TIMESTAMP)
.replace(now);
}
}
modifyCase(aCase, builder.asItemDeltas(), result);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.evolveum.midpoint.model.impl.correlator.CorrelatorUtil;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.util.CloneUtil;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
Expand Down Expand Up @@ -120,7 +121,7 @@ public CorrelationResult correlate(@NotNull ShadowType resourceObject, @NotNull
} else {
beans.correlationCaseManager.createOrUpdateCase(
resourceObject,
createSpecificCaseContext(mResult),
createSpecificCaseContext(mResult, resourceObject),
result);
return CorrelationResult.uncertain();
}
Expand All @@ -146,17 +147,22 @@ private CorrelationResult correlateUsingKnownReferenceId(
/**
* Converts internal {@link MatchingResult} into "externalized" {@link IdMatchCorrelationContextType} bean
* to be stored in the correlation case.
*
* _Temporarily_ adding also "none of the above" potential match here.
*/
private @NotNull IdMatchCorrelationContextType createSpecificCaseContext(MatchingResult mResult) {
private @NotNull IdMatchCorrelationContextType createSpecificCaseContext(
@NotNull MatchingResult mResult, @NotNull ShadowType resourceObject) {
IdMatchCorrelationContextType context = new IdMatchCorrelationContextType(PrismContext.get());
for (PotentialMatch potentialMatch : mResult.getPotentialMatches()) {
context.getPotentialMatch().add(
createPotentialMatchBean(potentialMatch));
createPotentialMatchBeanForExistingId(potentialMatch));
}
context.getPotentialMatch().add(
createPotentialMatchBeanForNewId(resourceObject));
return context;
}

private IdMatchCorrelationPotentialMatchType createPotentialMatchBean(PotentialMatch potentialMatch) {
private IdMatchCorrelationPotentialMatchType createPotentialMatchBeanForExistingId(PotentialMatch potentialMatch) {
String id = potentialMatch.getReferenceId();
return new IdMatchCorrelationPotentialMatchType(PrismContext.get())
.uri(qNameToUri(
Expand All @@ -166,6 +172,13 @@ private IdMatchCorrelationPotentialMatchType createPotentialMatchBean(PotentialM
.attributes(potentialMatch.getAttributes());
}

private IdMatchCorrelationPotentialMatchType createPotentialMatchBeanForNewId(@NotNull ShadowType resourceObject) {
return new IdMatchCorrelationPotentialMatchType(PrismContext.get())
.uri(SchemaConstants.CORRELATION_NONE_URI)
.attributes(
CloneUtil.clone(resourceObject.getAttributes()));
}

@Override
public void resolve(
@NotNull PrismObject<CaseType> aCase,
Expand Down

0 comments on commit 061e5d4

Please sign in to comment.