Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Sep 12, 2018
2 parents b323b92 + 7efd0f4 commit a978932
Show file tree
Hide file tree
Showing 30 changed files with 228 additions and 222 deletions.
Expand Up @@ -40,41 +40,41 @@ public class ObjectPaging implements DebugDumpable, Serializable {
protected ObjectPaging() {
}

ObjectPaging(Integer offset, Integer maxSize) {
private ObjectPaging(Integer offset, Integer maxSize) {
this.offset = offset;
this.maxSize = maxSize;
}

ObjectPaging(Integer offset, Integer maxSize, ItemPath groupBy) {
private ObjectPaging(Integer offset, Integer maxSize, ItemPath groupBy) {
this.offset = offset;
this.maxSize = maxSize;
setGrouping(groupBy);
}

ObjectPaging(ItemPath orderBy, OrderDirection direction) {
private ObjectPaging(ItemPath orderBy, OrderDirection direction) {
setOrdering(orderBy, direction);
}

ObjectPaging(ItemPath orderBy, OrderDirection direction, ItemPath groupBy) {
private ObjectPaging(ItemPath orderBy, OrderDirection direction, ItemPath groupBy) {
setOrdering(orderBy, direction);
setGrouping(groupBy);
}

ObjectPaging(Integer offset, Integer maxSize, ItemPath orderBy, OrderDirection direction) {
private ObjectPaging(Integer offset, Integer maxSize, ItemPath orderBy, OrderDirection direction) {
this.offset = offset;
this.maxSize = maxSize;
setOrdering(orderBy, direction);
}

ObjectPaging(Integer offset, Integer maxSize, ItemPath orderBy, OrderDirection direction, ItemPath groupBy) {
private ObjectPaging(Integer offset, Integer maxSize, ItemPath orderBy, OrderDirection direction, ItemPath groupBy) {
this.offset = offset;
this.maxSize = maxSize;
setOrdering(orderBy, direction);

setGrouping(groupBy);
}

ObjectPaging(ItemPath groupBy) {
private ObjectPaging(ItemPath groupBy) {
setGrouping(groupBy);
}

Expand Down
Expand Up @@ -309,18 +309,15 @@ private <O extends ObjectType> List<V> executeSearchAttempt(final List<PrismObje
}
extendOptions(options, searchOnResource);

ResultHandler<O> handler = new ResultHandler<O>() {
@Override
public boolean handle(PrismObject<O> object, OperationResult parentResult) {
if (rawResult != null) {
rawResult.add(object);
}
list.add(createPrismValue(object.getOid(), targetTypeQName, additionalAttributeDeltas, params));
ResultHandler<O> handler = (object, parentResult) -> {
if (rawResult != null) {
rawResult.add(object);
}
list.add(createPrismValue(object.getOid(), targetTypeQName, additionalAttributeDeltas, params));

// TODO: we should count results and stop after some reasonably high number?
// TODO: we should count results and stop after some reasonably high number?

return true;
}
return true;
};

try {
Expand Down
Expand Up @@ -149,7 +149,7 @@ private synchronized void initializeCustomFunctionsLibraryCache(ExpressionFactor
};
try {
repositoryService.searchObjectsIterative(FunctionLibraryType.class, null, functionLibraryHandler,
SelectorOptions.createCollection(GetOperationOptions.createReadOnly()), false, subResult);
SelectorOptions.createCollection(GetOperationOptions.createReadOnly()), true, subResult);
subResult.recordSuccessIfUnknown();
} catch (SchemaException | RuntimeException e) {
subResult.recordFatalError("Failed to initialize custom functions", e);
Expand Down
Expand Up @@ -194,9 +194,9 @@ public <T extends ObjectType> T getObject(Class<T> clazz, String oid, Collection
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);
provisioning.searchObjectsIterative(type, query, options, handler, task, parentResult);
} else {
cacheRepositoryService.searchObjectsIterative(type, query, handler, options, false, parentResult); // TODO pull up into resolver interface
cacheRepositoryService.searchObjectsIterative(type, query, handler, options, true, parentResult); // TODO pull up into resolver interface
}
}

Expand Down
Expand Up @@ -35,11 +35,7 @@
import com.evolveum.midpoint.prism.query.QueryJaxbConvertor;
import com.evolveum.midpoint.prism.query.builder.QueryBuilder;
import com.evolveum.midpoint.repo.api.CacheDispatcher;
import com.evolveum.midpoint.schema.DefinitionProcessingOption;
import com.evolveum.midpoint.schema.DeltaConvertor;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.ResultHandler;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.*;
import com.evolveum.midpoint.schema.constants.MidPointConstants;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.result.OperationResult;
Expand Down Expand Up @@ -462,13 +458,11 @@ public <T extends ObjectType> Response searchObjectsByType(@PathParam("type") St

Collection<SelectorOptions<GetOperationOptions>> searchOptions = GetOperationOptions.fromRestOptions(options, include, exclude, DefinitionProcessingOption.ONLY_IF_EXISTS);

List<T> objects = new ArrayList<>();
ResultHandler<T> handler = (object, parentResult1) -> objects.add(object.asObjectable());

modelService.searchObjectsIterative(clazz, null, handler, searchOptions, task, parentResult);

List<PrismObject<T>> objects = modelService.searchObjects(clazz, null, searchOptions, task, parentResult);
ObjectListType listType = new ObjectListType();
listType.getObject().addAll(objects);
for (PrismObject<T> object : objects) {
listType.getObject().add(object.asObjectable());
}

response = RestServiceUtil.createResponse(Response.Status.OK, listType, parentResult, true);
// response = Response.ok().entity(listType).build();
Expand Down
Expand Up @@ -1138,7 +1138,7 @@ public <T extends ObjectType> SearchResultMetadata searchObjectsIterative(Class<

try {
switch (searchProvider) {
case REPOSITORY: metadata = cacheRepositoryService.searchObjectsIterative(type, query, internalHandler, options, false, result); break; // TODO move strictSequential flag to model API in some form
case REPOSITORY: metadata = cacheRepositoryService.searchObjectsIterative(type, query, internalHandler, options, true, result); break;
case PROVISIONING: metadata = provisioning.searchObjectsIterative(type, query, options, internalHandler, task, result); break;
case TASK_MANAGER: metadata = taskManager.searchObjectsIterative(type, query, options, internalHandler, result); break;
default: throw new AssertionError("Unexpected search provider: " + searchProvider);
Expand Down
Expand Up @@ -493,7 +493,7 @@ private <F extends FocusType, T extends FocusType> void collectAutoassignMapping
}
return true;
};
cacheRepositoryService.searchObjectsIterative(AbstractRoleType.class, query, handler, GetOperationOptions.createReadOnlyCollection(), false, result);
cacheRepositoryService.searchObjectsIterative(AbstractRoleType.class, query, handler, GetOperationOptions.createReadOnlyCollection(), true, result);
}

private void setMappingTarget(MappingType mapping, ItemPathType path) {
Expand Down
Expand Up @@ -497,16 +497,13 @@ protected <O extends ObjectType> void searchObjectsIterative(Class<O> type, Obje
OperationResult result = task.getResult();
final MutableInt count = new MutableInt(0);
// Cannot convert to lambda here. Java does not want to understand the generic types properly.
SearchResultMetadata searchMetadata = modelService.searchObjectsIterative(type, query, new ResultHandler<O>() {
@Override
public boolean handle(PrismObject<O> object, OperationResult oresult) {
count.increment();
if (handler != null) {
handler.accept(object);
}
return true;
}
}, null, task, result);
SearchResultMetadata searchMetadata = modelService.searchObjectsIterative(type, query, (object, oresult) -> {
count.increment();
if (handler != null) {
handler.accept(object);
}
return true;
}, null, task, result);
if (verbose) display(type.getSimpleName()+"s", count.getValue());
assertEquals("Unexpected number of "+type.getSimpleName()+"s", expectedNumberOfObjects, count.getValue());
}
Expand Down Expand Up @@ -2162,12 +2159,9 @@ private void dumpOrg(StringBuilder sb, PrismObject<OrgType> org, int indent) {
protected void displayUsers() throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
Task task = taskManager.createTaskInstance(AbstractModelIntegrationTest.class+".displayUsers");
OperationResult result = task.getResult();
ResultHandler<UserType> handler = new ResultHandler<UserType>() {
@Override
public boolean handle(PrismObject<UserType> user, OperationResult parentResult) {
display("User", user);
return true;
}
ResultHandler<UserType> handler = (user, parentResult) -> {
display("User", user);
return true;
};
modelService.searchObjectsIterative(UserType.class, null, handler, null, task, result);
result.computeStatus();
Expand Down Expand Up @@ -4184,12 +4178,9 @@ protected void assertSecurityContextNoAuthorizationActions() {
protected void displayAllUsers() throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
Task task = taskManager.createTaskInstance(AbstractModelIntegrationTest.class.getName() + ".displayAllUsers");
OperationResult result = task.getResult();
ResultHandler<UserType> handler = new ResultHandler<UserType>() {
@Override
public boolean handle(PrismObject<UserType> object, OperationResult parentResult) {
display("User", object);
return true;
}
ResultHandler<UserType> handler = (object, parentResult) -> {
display("User", object);
return true;
};
modelService.searchObjectsIterative(UserType.class, null, handler, null, task, result);
result.computeStatus();
Expand Down
Expand Up @@ -1000,7 +1000,7 @@ public <T extends ObjectType> SearchResultMetadata searchObjectsIterative(final

try {

metadata = getCacheRepositoryService().searchObjectsIterative(type, query, internalHandler, repoOptions, false, result); // TODO think about strictSequential flag
metadata = getCacheRepositoryService().searchObjectsIterative(type, query, internalHandler, repoOptions, true, result);

result.computeStatus();
result.recordSuccessIfUnknown();
Expand Down
Expand Up @@ -711,7 +711,7 @@ public SearchResultMetadata searchObjectsIterativeRepository(
ObjectQuery repoQuery = query.clone();
processQueryMatchingRules(repoQuery, ctx.getObjectClassDefinition());

return repositoryService.searchObjectsIterative(ShadowType.class, repoQuery, repoHandler, options, false, parentResult); // TODO think about strictSequential flag
return repositoryService.searchObjectsIterative(ShadowType.class, repoQuery, repoHandler, options, true, parentResult);
}

/**
Expand Down
Expand Up @@ -218,11 +218,10 @@ private ObjectQuery createQueryBySecondaryIdentifier(ShadowType shadow) throws S
* Note: this may return dead shadow.
*/
private List<PrismObject<ShadowType>> findConflictingShadowsInRepo(ObjectQuery query, Task task, OperationResult parentResult)
throws ObjectNotFoundException, CommunicationException, ConfigurationException, SchemaException,
SecurityViolationException, ExpressionEvaluationException {
throws SchemaException {
final List<PrismObject<ShadowType>> foundAccount = new ArrayList<>();

repositoryService.searchObjectsIterative(ShadowType.class, query, (object,result) -> foundAccount.add(object), null, false, parentResult);
repositoryService.searchObjectsIterative(ShadowType.class, query, (object,result) -> foundAccount.add(object), null, true, parentResult);

return foundAccount;
}
Expand Down
Expand Up @@ -22,7 +22,6 @@
import com.evolveum.midpoint.prism.query.builder.QueryBuilder;
import com.evolveum.midpoint.provisioning.impl.ShadowCache;
import com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException;
import com.evolveum.midpoint.repo.api.PreconditionViolationException;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.repo.common.task.AbstractSearchIterativeResultHandler;
import com.evolveum.midpoint.schema.ResultHandler;
Expand Down Expand Up @@ -55,7 +54,7 @@ public MultiPropagationResultHandler(Task coordinatorTask, String taskOperationP

@Override
protected boolean handleObject(PrismObject<ResourceType> resource, Task workerTask, OperationResult taskResult)
throws CommonException, PreconditionViolationException {
throws CommonException {

LOGGER.trace("Propagating provisioning operations on {}", resource);
ObjectQuery query = new ObjectQuery();
Expand All @@ -72,7 +71,7 @@ protected boolean handleObject(PrismObject<ResourceType> resource, Task workerTa
return true;
};

repositoryService.searchObjectsIterative(ShadowType.class, query, handler, null, false, taskResult);
repositoryService.searchObjectsIterative(ShadowType.class, query, handler, null, true, taskResult);

LOGGER.trace("Propagation of {} done", resource);

Expand Down
Expand Up @@ -2361,7 +2361,7 @@ public boolean handle(PrismObject<ShadowType> shadow, OperationResult parentResu
displayWhen(TEST_NAME);
SearchResultMetadata searchMetadata;
if (useRepo) {
searchMetadata = repositoryService.searchObjectsIterative(ShadowType.class, query, handler, null, false, result);
searchMetadata = repositoryService.searchObjectsIterative(ShadowType.class, query, handler, null, true, result);
} else {
searchMetadata = provisioningService.searchObjectsIterative(ShadowType.class, query, options, handler, null, result);
}
Expand Down
Expand Up @@ -1418,14 +1418,11 @@ protected void assertShadows(int expectedCount) throws SchemaException {
OperationResult result = new OperationResult(TestOpenDj.class.getName() + ".assertShadows");
int actualCount = repositoryService.countObjects(ShadowType.class, null, null, result);
if (actualCount != expectedCount) {
ResultHandler<ShadowType> handler = new ResultHandler<ShadowType>() {
@Override
public boolean handle(PrismObject<ShadowType> object, OperationResult parentResult) {
display("Repo shadow", object);
return true;
}
ResultHandler<ShadowType> handler = (object, parentResult) -> {
display("Repo shadow", object);
return true;
};
repositoryService.searchObjectsIterative(ShadowType.class, null, handler, null, false, result);
repositoryService.searchObjectsIterative(ShadowType.class, null, handler, null, true, result);
assertEquals("Unexpected number of shadows in the repo", expectedCount, actualCount);
}
}
Expand Down
Expand Up @@ -297,17 +297,41 @@ <T extends Containerable> SearchResultList<T> searchContainers(Class<T> type, Ob
* @param handler
* result handler
* @param strictlySequential
* takes care not to skip any object nor to process objects more than once;
* currently requires paging NOT to be used - uses its own paging
* takes care not to skip any object nor to process objects more than once; see below
* @param parentResult
* parent OperationResult (in/out)
* @return all objects of specified type that match search criteria (subject
* to paging)
* @return all objects of specified type that match search criteria (subject to paging)
*
* @throws IllegalArgumentException
* wrong object type
* @throws SchemaException
* unknown property used in search query
*
* A note related to iteration method:
*
* There are three iteration methods (see IterationMethodType):
* - SINGLE_TRANSACTION: Fetches objects in single DB transaction. Not supported for all DBMSs.
* - SIMPLE_PAGING: Uses the "simple paging" method: takes objects (e.g.) numbered 0 to 49, then 50 to 99,
* then 100 to 149, and so on. The disadvantage is that if the order of objects is changed
* during operation (e.g. by inserting/deleting some of them) then some objects can be
* processed multiple times, where others can be skipped.
* - STRICTLY_SEQUENTIAL_PAGING: Uses the "strictly sequential paging" method: sorting returned objects by OID. This
* is (almost) reliable in such a way that no object would be skipped. However, custom
* paging cannot be used in this mode.
*
* If GetOperationOptions.iterationMethod is specified, it is used without any further considerations.
* Otherwise, the repository configuration determines whether to use SINGLE_TRANSACTION or a paging. In the latter case,
* strictlySequential flag determines between SIMPLE_PAGING (if false) and STRICTLY_SEQUENTIAL_PAGING (if true).
*
* If explicit GetOperationOptions.iterationMethod is not provided, and paging is prescribed, and strictlySequential flag
* is true and client-provided paging conflicts with the paging used by the iteration method, a warning is issued, and
* iteration method is switched to SIMPLE_PAGING.
*
* Sources of conflicts:
* - ordering is specified
* - offset is specified
* (limit is not a problem)
*
*/

<T extends ObjectType> SearchResultMetadata searchObjectsIterative(Class<T> type, ObjectQuery query,
Expand Down
Expand Up @@ -352,12 +352,9 @@ public <T extends ObjectType> SearchResultMetadata searchObjectsIterative(Class<
// TODO use cached query result if applicable
log("Cache: PASS searchObjectsIterative ({})", type.getSimpleName());
final Cache cache = getCache();
ResultHandler<T> myHandler = new ResultHandler<T>() {
@Override
public boolean handle(PrismObject<T> object, OperationResult parentResult) {
cacheObject(cache, object, GetOperationOptions.isReadOnly(SelectorOptions.findRootOptions(options)));
return handler.handle(object, parentResult);
}
ResultHandler<T> myHandler = (object, parentResult1) -> {
cacheObject(cache, object, GetOperationOptions.isReadOnly(SelectorOptions.findRootOptions(options)));
return handler.handle(object, parentResult1);
};
Long startTime = repoOpStart();
try {
Expand Down

0 comments on commit a978932

Please sign in to comment.