Skip to content

Commit

Permalink
MID-8616: cleanup, ObjectReferenceType->Referencable where sufficient
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed Mar 21, 2023
1 parent e5575da commit 2afb9a1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/*
* Copyright (C) 2010-2020 Evolveum and contributors
* Copyright (C) 2010-2023 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.model.impl;

import static com.evolveum.midpoint.model.impl.controller.ModelController.getObjectManager;
import static com.evolveum.midpoint.schema.GetOperationOptions.createReadOnlyCollection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -40,9 +43,6 @@
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import static com.evolveum.midpoint.model.impl.controller.ModelController.*;
import static com.evolveum.midpoint.schema.GetOperationOptions.createReadOnlyCollection;

@Component
public class ModelObjectResolver implements ObjectResolver {

Expand All @@ -56,7 +56,7 @@ public class ModelObjectResolver implements ObjectResolver {

@Override
public <O extends ObjectType> O resolve(
ObjectReferenceType ref,
Referencable ref,
Class<O> expectedType,
Collection<SelectorOptions<GetOperationOptions>> options,
String contextDescription,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2018 Evolveum and contributors
* Copyright (C) 2010-2023 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand All @@ -10,7 +10,11 @@
import java.io.IOException;
import java.util.Collection;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.Referencable;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
import com.evolveum.midpoint.schema.GetOperationOptions;
Expand All @@ -19,52 +23,41 @@
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.ExpressionEvaluationException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SecurityViolationException;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FunctionLibraryType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Object resolver that works on files in a directory.
* This is only used in tests. But due to complicated dependencies this is
* part of main code. That does not hurt much.
*
* @author Radovan Semancik
*
*/
public class DirectoryFileObjectResolver implements ObjectResolver {

private File directory;
private final File directory;

public DirectoryFileObjectResolver(File directory) {
super();
this.directory = directory;
}

@Override
public <T extends ObjectType> T resolve(ObjectReferenceType ref, Class<T> expectedType,
Collection<SelectorOptions<GetOperationOptions>> options, String contextDescription,
Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
public <T extends ObjectType> T resolve(Referencable ref, Class<T> expectedType,
Collection<SelectorOptions<GetOperationOptions>> options, String contextDescription,
Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
return getObject(expectedType, ref.getOid(), options, task, result);
}

private String oidToFilename(String oid) {
return oid+".xml";
return oid + ".xml";
}

@Override
public <O extends ObjectType> void searchIterative(Class<O> type, ObjectQuery query,
Collection<SelectorOptions<GetOperationOptions>> options, ResultHandler<O> handler,
Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException,
Collection<SelectorOptions<GetOperationOptions>> options, ResultHandler<O> handler,
Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException,
CommunicationException, ConfigurationException, SecurityViolationException {
//TODO: do we want to test custom libraries in the "unit" tests
if (type.equals(FunctionLibraryType.class)) {
Expand All @@ -88,11 +81,11 @@ public <T extends ObjectType> T getObject(
@Nullable Task task,
@NotNull OperationResult result)
throws ObjectNotFoundException, SchemaException {
File file = new File( directory, oidToFilename(oid));
File file = new File(directory, oidToFilename(oid));
if (file.exists()) {
try {
//noinspection unchecked
return (T)PrismTestUtil.parseObject(file).asObjectable();
return (T) PrismTestUtil.parseObject(file).asObjectable();
} catch (IOException e) {
throw new SystemException(e.getMessage(), e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2018 Evolveum and contributors
* Copyright (C) 2010-2023 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand All @@ -10,30 +10,25 @@
import java.util.HashMap;
import java.util.Map;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.prism.Referencable;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.ResultHandler;
import com.evolveum.midpoint.schema.SearchResultList;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.ExpressionEvaluationException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SecurityViolationException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* The callback from some of the object utilities to resolve objects.
* The callback from some object utilities to resolve objects.
*
* The classes implementing this will most likely fetch the objects from the
* repository or from some kind of object cache.
Expand All @@ -50,19 +45,15 @@ public interface ObjectResolver {
*
* @param ref object reference to resolve
* @param contextDescription short description of the context of resolution, e.g. "executing expression FOO". Used in error messages.
* @param task
* @return resolved object
* @throws ObjectNotFoundException
* requested object does not exist
* @throws SchemaException
* error dealing with storage schema
* @throws IllegalArgumentException
* wrong OID format, etc.
* @throws ObjectNotFoundException requested object does not exist
* @throws SchemaException error dealing with storage schema
* @throws IllegalArgumentException wrong OID format, etc.
*
* TODO resolve module dependencies to allow task to be of type Task
*/
<O extends ObjectType> O resolve(
ObjectReferenceType ref,
Referencable ref,
Class<O> expectedType,
Collection<SelectorOptions<GetOperationOptions>> options,
String contextDescription,
Expand Down Expand Up @@ -100,7 +91,7 @@ interface Session {

default Session openResolutionSession(GetOperationOptions options) {
return new Session() {
private Map<String, PrismObject<?>> objects = new HashMap<>();
private final Map<String, PrismObject<?>> objects = new HashMap<>();

@Override
public GetOperationOptions getOptions() {
Expand Down Expand Up @@ -128,5 +119,4 @@ default void resolveReference(PrismReferenceValue ref, String contextDescription
Session session, Object task, OperationResult result) {
throw new UnsupportedOperationException();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017-2020 Evolveum and contributors
* Copyright (C) 2017-2023 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand All @@ -14,6 +14,7 @@
import org.springframework.beans.factory.annotation.Qualifier;

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.Referencable;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.schema.GetOperationOptions;
Expand All @@ -24,7 +25,6 @@
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

/**
Expand Down Expand Up @@ -55,7 +55,7 @@ public <O extends ObjectType> SearchResultList<PrismObject<O>> searchObjects(Cla
}

@Override
public <O extends ObjectType> O resolve(ObjectReferenceType ref, Class<O> expectedType,
public <O extends ObjectType> O resolve(Referencable ref, Class<O> expectedType,
Collection<SelectorOptions<GetOperationOptions>> options, String contextDescription, Task task,
OperationResult result) {
// TODO Auto-generated method stub
Expand All @@ -72,5 +72,4 @@ public <O extends ObjectType> O getObject(
throws ObjectNotFoundException, SchemaException {
return cacheRepositoryService.getObject(expectedType, oid, options, parentResult).asObjectable();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import java.util.stream.Collectors;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.schema.GetOperationOptionsBuilder;

import groovy.lang.GString;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
Expand All @@ -41,6 +39,7 @@
import com.evolveum.midpoint.repo.common.ObjectResolver;
import com.evolveum.midpoint.schema.AccessDecision;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.GetOperationOptionsBuilder;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.constants.ExpressionConstants;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
Expand Down Expand Up @@ -247,7 +246,7 @@ public static TypedValue<?> convertVariableValue(
TypedValue<?> convertedTypedValue = originalTypedValue.shallowClone();
convertedTypedValue.setPrismContext(prismContext);

if (convertedTypedValue.getValue() instanceof ObjectReferenceType) {
if (convertedTypedValue.getValue() instanceof Referencable) {
convertedTypedValue = resolveReference(convertedTypedValue,
variableName, objectResolver, contextDescription, objectVariableMode,
task, result);
Expand Down Expand Up @@ -398,9 +397,9 @@ private static TypedValue<?> resolveReference(TypedValue<?> referenceTypedValue,
CommunicationException, ConfigurationException, SecurityViolationException,
ExpressionEvaluationException {
TypedValue<?> resolvedTypedValue;
ObjectReferenceType originalReference = (ObjectReferenceType) referenceTypedValue.getValue();
Referencable originalReference = (Referencable) referenceTypedValue.getValue();
Itemable originalParent = originalReference.asReferenceValue().getParent();
ObjectReferenceType reference = originalReference.clone();
Referencable reference = originalReference.clone();
OperationResult subResult = result.createMinorSubresult(OP_RESOLVE_REFERENCE);
try {
GetOperationOptionsBuilder builder = GetOperationOptionsBuilder.create().allowNotFound();
Expand Down Expand Up @@ -450,7 +449,7 @@ static TypedValue<PrismObject<?>> resolveReference(TypedValue<?> refAndDef, Obje
Task task, OperationResult result)
throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException,
SecurityViolationException, ExpressionEvaluationException {
ObjectReferenceType ref = (ObjectReferenceType) refAndDef.getValue();
Referencable ref = (Referencable) refAndDef.getValue();
if (ref.getOid() == null) {
throw new SchemaException(
"Null OID in reference in variable " + varDesc + " in " + contextDescription);
Expand Down

0 comments on commit 2afb9a1

Please sign in to comment.