Skip to content

Commit

Permalink
Fix object type determination for kind=null
Browse files Browse the repository at this point in the history
Incorrect method was used. Now model-intest tests should pass.
  • Loading branch information
mederly committed May 30, 2022
1 parent a6a3310 commit 57f24b3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import static com.evolveum.midpoint.util.MiscUtil.argCheck;

Expand Down Expand Up @@ -118,6 +119,21 @@ public class ResourceObjectDefinitionResolver {
return getDefinitionForShadow(resourceSchema, shadow.asObjectable());
}

/**
* Looks up appropriate definition for "bulk operation" i.e. operation that is executed for given kind/intent/objectclass
* on given resource.
*
* Currently, this is the same as {@link #getObjectDefinitionPrecisely(ResourceType, ShadowKindType, String, QName,
* Collection, boolean)} with no additional aux OCs and unknown values not supported.
*/
public static @Nullable ResourceObjectDefinition getForBulkOperation(
@NotNull ResourceType resource,
@Nullable ShadowKindType kind,
@Nullable String intent,
@Nullable QName objectClassName) throws SchemaException, ConfigurationException {
return getObjectDefinitionPrecisely(resource, kind, intent, objectClassName, List.of(), false);
}

/**
* Determines object type/class definition in a precise way. The decision is based on kind/intent/objectclass triple,
* and later enriched by aux object class names.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.annotation.Experimental;
import com.evolveum.midpoint.util.exception.CommonException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
Expand Down Expand Up @@ -112,18 +113,24 @@ public static ProcessingScope of(
@NotNull ResourceObjectSetType resourceObjectSet)
throws ActivityRunException {

ResourceSchema resourceSchema = getCompleteSchema(resource);

ShadowKindType kind = resourceObjectSet.getKind();
String intent = resourceObjectSet.getIntent();
QName objectClassName = resourceObjectSet.getObjectclass();

ResourceObjectDefinition objectDefinition = resourceSchema.findObjectDefinition(kind, intent, objectClassName);
if (objectDefinition == null) {
ResourceObjectDefinition definition;
try {
definition = ResourceObjectDefinitionResolver.getForBulkOperation(resource, kind, intent, objectClassName);
} catch (CommonException e) {
throw new ActivityRunException(
"Couldn't determine object definition for " + kind + "/" + intent + "/" + objectClassName + " on " + resource,
FATAL_ERROR, PERMANENT_ERROR, e);
}

if (definition == null) {
LOGGER.debug("Processing all object classes");
}

return new ProcessingScope(resource, objectDefinition, kind, intent, objectClassName);
return new ProcessingScope(resource, definition, kind, intent, objectClassName);
}

/** See the note in class-level javadoc. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ public ProcessingScope createProcessingScopeForShadow(
return resourceOid;
}

private @NotNull ResourceType getResource(String resourceOid, Task task, OperationResult opResult) throws ActivityRunException {
private @NotNull ResourceType getResource(String resourceOid, Task task, OperationResult opResult)
throws ActivityRunException {
try {
return provisioningService
.getObject(ResourceType.class, resourceOid, createReadOnlyCollection(), task, opResult)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,8 @@ private ScopedDefinition createScopedDefinitionForBulkOperation(ResourceShadowCo
String intent = coords.getIntent();
QName objectClassName = coords.getObjectClass();

ResourceObjectDefinition definition = ResourceObjectDefinitionResolver.getObjectDefinitionPrecisely(
resource,
kind,
intent,
objectClassName,
List.of(),
false);
ResourceObjectDefinition definition =
ResourceObjectDefinitionResolver.getForBulkOperation(resource, kind, intent, objectClassName);

Boolean wholeClass;
if (kind != null) {
Expand Down

0 comments on commit 57f24b3

Please sign in to comment.