Skip to content

Commit

Permalink
Fixing ObjectResolver vs SimpleObjectResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Aug 28, 2018
1 parent 59ec9cc commit f87ffe0
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 15 deletions.
Expand Up @@ -82,7 +82,7 @@ public <R extends ObjectType> void resolve(ResultHandler<R> handler, ProhibitedV
handleObject(handler, result);
break;
case OWNER:
handleOwner(handler, contextDescription, result);
handleOwner(handler, contextDescription, task, result);
break;
case PERSONA:
handlePersonas(handler, contextDescription, task, result);
Expand Down Expand Up @@ -156,8 +156,8 @@ private <P extends ObjectType> void handleProjections(ResultHandler<P> handler,
}
}

private <P extends ObjectType> void handleOwner(ResultHandler<P> handler, String contextDescription, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
private <P extends ObjectType> void handleOwner(ResultHandler<P> handler, String contextDescription, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
objectResolver.searchIterative(getOwnerClass(), getOwnerQuery(), SelectorOptions.createCollection(GetOperationOptions.createReadOnly()),
handler, "resolving owner in " + contextDescription, result);
handler, task, result);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2017 Evolveum
* Copyright (c) 2010-2018 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -191,7 +191,7 @@ public <T extends ObjectType> T getObject(Class<T> clazz, String oid, Collection
}

@Override
public <O extends ObjectType> void searchIterative(Class<O> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, ResultHandler<O> handler, Object task, OperationResult parentResult)
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, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
if (ObjectTypes.isClassManagedByProvisioning(type)) {
provisioning.searchObjectsIterative(type, query, options, handler, (Task) task, parentResult);
Expand Down
Expand Up @@ -104,7 +104,7 @@ public <FO extends FocusType, O extends ObjectType> PrismObject<FO> resolveOwner
.item(FocusType.F_PERSONA_REF).ref(object.getOid()).build();
List<PrismObject<UserType>> owners = new ArrayList<>();
try {
objectResolver.searchIterative(UserType.class, query, null, (o,result) -> owners.add(o), owners, result);
objectResolver.searchIterative(UserType.class, query, null, (o,result) -> owners.add(o), task, result);
} catch (ObjectNotFoundException | CommunicationException | ConfigurationException
| SecurityViolationException | SchemaException | ExpressionEvaluationException e) {
LOGGER.warn("Cannot resolve owner of {}: {}", object, e.getMessage(), e);
Expand Down
Expand Up @@ -102,7 +102,7 @@ protected <O extends ObjectType> Integer countObjects(Class<O> type, ObjectQuery
}

@Override
protected <O extends ObjectType> void searchIterative(Class<O> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> searchOptions, ResultHandler<O> resultHandler, Object coordinatorTask, OperationResult opResult)
protected <O extends ObjectType> void searchIterative(Class<O> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> searchOptions, ResultHandler<O> resultHandler, Task coordinatorTask, OperationResult opResult)
throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
modelObjectResolver.searchIterative(type, query, searchOptions, resultHandler, coordinatorTask, opResult);
}
Expand Down
Expand Up @@ -5367,7 +5367,7 @@ protected PendingOperationType findPendingOperation(PrismObject<ShadowType> shad

protected void initializeAsserter(AbstractAsserter<?> asserter) {
asserter.setPrismContext(prismContext);
asserter.setObjectResolver(repoObjectResolver);
asserter.setObjectResolver(repoSimpleObjectResolver);
}

protected UserAsserter<Void> assertUserAfter(String oid) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
Expand Down
Expand Up @@ -68,7 +68,7 @@ private String oidToFilename(String oid) {
@Override
public <O extends ObjectType> void searchIterative(Class<O> type, ObjectQuery query,
Collection<SelectorOptions<GetOperationOptions>> options, ResultHandler<O> handler,
Object task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException,
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 Down
Expand Up @@ -73,7 +73,7 @@ <O extends ObjectType> O resolve(ObjectReferenceType ref, Class<O> expectedType,
<O extends ObjectType> O getObject(Class<O> clazz, String oid, Collection<SelectorOptions<GetOperationOptions>> options, Task task,
OperationResult result) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException;

<O extends ObjectType> void searchIterative(Class<O> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, ResultHandler<O> handler, Object task, OperationResult parentResult)
<O extends ObjectType> void searchIterative(Class<O> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, ResultHandler<O> handler, Task task, OperationResult parentResult)
throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException;

// EXPERIMENTAL (implemented only for ModelObjectResolver)
Expand Down
@@ -0,0 +1,88 @@
/**
* Copyright (c) 2017-2018 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.repo.common;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.ResultHandler;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.SimpleObjectResolver;
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.xml.ns._public.common.common_3.ObjectType;

/**
* 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 RepoObjectResolver implements ObjectResolver {

@Autowired(required = true)
private transient PrismContext prismContext;

@Autowired(required = true)
@Qualifier("cacheRepositoryService")
private transient RepositoryService cacheRepositoryService;


@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, CommunicationException, ConfigurationException,
SecurityViolationException, ExpressionEvaluationException {

cacheRepositoryService.searchObjectsIterative(type, query, handler, options, false, parentResult);
}

@Override
public <O extends ObjectType> O resolve(ObjectReferenceType ref, Class<O> expectedType,
Collection<SelectorOptions<GetOperationOptions>> options, String contextDescription, Task task,
OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException,
ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
// TODO Auto-generated method stub
return null;
}

@Override
public <O extends ObjectType> O getObject(Class<O> expectedType, String oid,
Collection<SelectorOptions<GetOperationOptions>> options, Task task, OperationResult parentResult)
throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException,
SecurityViolationException, ExpressionEvaluationException {
return cacheRepositoryService.getObject(expectedType, oid, options, parentResult).asObjectable();
}



}
Expand Up @@ -445,7 +445,7 @@ protected <O extends ObjectType> Integer countObjects(Class<O> type, ObjectQuery
/**
* Used to search using model or any similar higher-level interface. Defaults to search using repository.
*/
protected <O extends ObjectType> void searchIterative(Class<O> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> searchOptions, ResultHandler<O> resultHandler, Object coordinatorTask, OperationResult opResult)
protected <O extends ObjectType> void searchIterative(Class<O> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> searchOptions, ResultHandler<O> resultHandler, Task coordinatorTask, OperationResult opResult)
throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
repositoryService.searchObjectsIterative(type, query, resultHandler, searchOptions, false, opResult); // TODO think about this
}
Expand Down
Expand Up @@ -186,8 +186,8 @@ public abstract class AbstractIntegrationTest extends AbstractTestNGSpringContex
@Autowired protected LocalizationService localizationService;

@Autowired(required = false)
@Qualifier("repoObjectResolver")
protected SimpleObjectResolver repoObjectResolver;
@Qualifier("repoSimpleObjectResolver")
protected SimpleObjectResolver repoSimpleObjectResolver;

// Controllers for embedded OpenDJ and Derby. The abstract test will configure it, but
// it will not start
Expand Down
Expand Up @@ -41,7 +41,7 @@
* @author semancik
*
*/
public class RepoObjectResolver implements SimpleObjectResolver {
public class RepoSimpleObjectResolver implements SimpleObjectResolver {

@Autowired(required = true)
private transient PrismContext prismContext;
Expand Down
Expand Up @@ -29,7 +29,7 @@

<!-- Definition of basic expression factory - just with simple evaluators -->

<bean id="repoObjectResolver" class="com.evolveum.midpoint.test.RepoObjectResolver" />
<bean id="repoObjectResolver" class="com.evolveum.midpoint.repo.common.RepoObjectResolver" />

<bean id="expressionFactory" class="com.evolveum.midpoint.repo.common.expression.ExpressionFactory"
scope="singleton">
Expand Down

0 comments on commit f87ffe0

Please sign in to comment.