Skip to content

Commit

Permalink
Fix classifier API
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Feb 16, 2021
1 parent 67b4751 commit 6a35c59
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 33 deletions.
Expand Up @@ -41,21 +41,17 @@ void destroy() {
}

@Override
public @NotNull Classification classify(@NotNull PrismObject<ShadowType> resourceObject,
@NotNull PrismObject<ResourceType> resource, @NotNull PrismObject<ShadowType> repoShadow,
@NotNull Task task, @NotNull OperationResult parentResult)
public @NotNull Classification classify(@NotNull PrismObject<ShadowType> combinedObject,
@NotNull PrismObject<ResourceType> resource, @NotNull Task task, @NotNull OperationResult parentResult)
throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException,
ConfigurationException, ExpressionEvaluationException {

// TODO clarify resourceObject vs. repoShadow -- currently we send there "combined" resource object plus shadow

OperationResult result = parentResult.subresult(OP_CLASSIFY)
.addParam("resourceObject", resourceObject)
.addParam("repoShadow", repoShadow)
.addParam("combinedObject", combinedObject)
.addParam("resource", resource)
.build();
try {
return doClassify(resourceObject, resource, repoShadow, task, result);
return doClassify(combinedObject, resource, task, result);
} catch (Throwable t) {
result.recordFatalError(t);
throw t;
Expand All @@ -64,31 +60,31 @@ void destroy() {
}
}

private Classification doClassify(PrismObject<ShadowType> resourceObject, PrismObject<ResourceType> resource,
PrismObject<ShadowType> repoShadow, Task task, OperationResult result)
private Classification doClassify(PrismObject<ShadowType> combinedObject, PrismObject<ResourceType> resource,
Task task, OperationResult result)
throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException,
ConfigurationException, ExpressionEvaluationException {

PrismObject<SystemConfigurationType> configuration = systemObjectCache.getSystemConfiguration(result);
SynchronizationContext<?> syncCtx = synchronizationService.loadSynchronizationContext(
repoShadow, resourceObject, null, resource,
combinedObject, combinedObject, null, resource,
task.getCategory(), null, configuration, task, result);

return createClassification(repoShadow, syncCtx);
return createClassification(combinedObject, syncCtx);
}

@NotNull
private Classification createClassification(PrismObject<ShadowType> repoShadow, SynchronizationContext<?> syncCtx)
private Classification createClassification(PrismObject<ShadowType> combinedObject, SynchronizationContext<?> syncCtx)
throws SchemaException {
ShadowType shadowBean = repoShadow.asObjectable();
ShadowType objectBean = combinedObject.asObjectable();

// This is how original synchronization service was implemented: it did not overwrite previously known values.
ShadowKindType newKind = ShadowUtil.isKnown(shadowBean.getKind()) ? shadowBean.getKind() : syncCtx.getKind();
String newIntent = ShadowUtil.isKnown(shadowBean.getIntent()) ? shadowBean.getIntent() : syncCtx.getIntent();
ShadowKindType newKind = ShadowUtil.isKnown(objectBean.getKind()) ? objectBean.getKind() : syncCtx.getKind();
String newIntent = ShadowUtil.isKnown(objectBean.getIntent()) ? objectBean.getIntent() : syncCtx.getIntent();

// And as for the tag, currently it creates syncCtx.tag value only if it really wants it to be changed.
// Otherwise it is null.
String newTag = shadowBean.getTag() != null ? shadowBean.getTag() : syncCtx.getTag();
String newTag = objectBean.getTag() != null ? objectBean.getTag() : syncCtx.getTag();

return new Classification(newKind, newIntent, newTag);
}
Expand Down
Expand Up @@ -6,10 +6,7 @@
*/
package com.evolveum.midpoint.model.impl.util.mock;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.*;

import com.evolveum.midpoint.util.exception.CommonException;

Expand Down Expand Up @@ -202,7 +199,7 @@ public <T extends Containerable> int countContainers(Class<T> type, ObjectQuery

@Override
public <T extends ObjectType> @NotNull String addObject(@NotNull PrismObject<T> object, RepoAddOptions options, @NotNull OperationResult parentResult) {
return null;
return UUID.randomUUID().toString();
}

@NotNull
Expand Down
Expand Up @@ -23,17 +23,18 @@
public interface ResourceObjectClassifier {

/**
* Classifies the resource object. The object may or may not be adopted (i.e. connected to its repository shadow).
* Classifies the shadowed resource object.
*
* TODO clarify resourceObject vs. repoShadow -- currently we send there "combined" resource object plus shadow
* @param combinedObject Resource object that we want to classify. It should be connected to the shadow,
* however, exact "shadowization" is not required. Currently it should contain all the information from the shadow,
* plus all the attributes from resource object. If needed, more elaborate processing (up to full shadowization)
* can be added later.
*
* @param resourceObject Resource object that we want to classify
* @param resource Resource on which the resource object was found
* @param repoShadow The current repository shadow associated with the resource object.
* It is needed e.g. to determine the tag value.
*/
@NotNull Classification classify(@NotNull PrismObject<ShadowType> resourceObject, @NotNull PrismObject<ResourceType> resource,
@NotNull PrismObject<ShadowType> repoShadow, @NotNull Task task, @NotNull OperationResult result)
@NotNull Classification classify(@NotNull PrismObject<ShadowType> combinedObject,
@NotNull PrismObject<ResourceType> resource,
@NotNull Task task, @NotNull OperationResult result)
throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException,
ConfigurationException, ExpressionEvaluationException;

Expand Down
Expand Up @@ -68,12 +68,11 @@ public void classify(ProvisioningContext ctx, PrismObject<ShadowType> shadow, Pr

argCheck(shadow.getOid() != null, "Shadow has no OID");

// The classifier code does not quite distinguish between resourceObject and the shadow.
// As an ugly hack let us create "combined" version of the two, and present that to the classifier.
// The classifier code works with the "combined" version of resource object and its shadow.
// This is NOT a full shadowization. Just good enough for the classifier to work.
PrismObject<ShadowType> combinedObject = combine(resourceObject, shadow);

Classification classification = classifier.classify(combinedObject, ctx.getResource().asPrismObject(), combinedObject,
Classification classification = classifier.classify(combinedObject, ctx.getResource().asPrismObject(),
ctx.getTask(), result);

if (isDifferent(classification, shadow)) {
Expand All @@ -85,7 +84,7 @@ public void classify(ProvisioningContext ctx, PrismObject<ShadowType> shadow, Pr
}

/**
* The combination simply takes attributes and associations from the resource object, and the rest from the shadow.
* The combination simply takes attributes from the resource object, and the rest from the shadow.
* It is much simplified version of what is done in {@link ShadowedObjectConstruction}. We hope if will suffice for now.
* In particular, we hope that the object class is roughly OK, and things like entitlement, credentials, and so on
* are not needed.
Expand Down

0 comments on commit 6a35c59

Please sign in to comment.