use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.
the class OrgClosureManager method rebuild.
// endregion
// region Rebuilding or checking org closure
// we are already in the context of a transaction (and the org struct table is locked if possible)
// "check" here means "thorough check" (i.e. comparing with recomputed closure)
private void rebuild(boolean check, boolean rebuild, boolean stopOnFailure, final Context context, final Session session, OperationResult result) throws SchemaException {
List existingEntries = null;
if (check) {
LOGGER.info("Reading from existing org closure table");
NativeQuery selectQuery = session.createNativeQuery("SELECT descendant_oid, ancestor_oid, val from " + CLOSURE_TABLE_NAME).addScalar("descendant_oid", StringType.INSTANCE).addScalar("ancestor_oid", StringType.INSTANCE).addScalar("val", IntegerType.INSTANCE);
existingEntries = selectQuery.list();
LOGGER.info("{} entries read", existingEntries.size());
}
LOGGER.info("Computing org closure table from scratch");
NativeQuery deleteQuery = session.createNativeQuery("delete from " + CLOSURE_TABLE_NAME);
deleteQuery.executeUpdate();
LOGGER.trace("Closure table content deleted");
final int orgsTotal = repositoryService.countObjects(OrgType.class, null, null, result);
final MutableInt orgsProcessed = new MutableInt(0);
ResultHandler<OrgType> handler = new ResultHandler<OrgType>() {
@Override
public boolean handle(PrismObject<OrgType> object, OperationResult parentResult) {
LOGGER.trace("Processing {}", object);
handleAdd(object.getOid(), getParentOidsFromObject(object), context, session);
orgsProcessed.add(1);
int currentState = orgsProcessed.intValue();
if (currentState % 100 == 0) {
LOGGER.info("{} organizations processed (out of {})", currentState, orgsTotal);
}
return true;
}
};
repositoryService.searchObjectsIterative(OrgType.class, null, handler, null, true, result);
LOGGER.info("Org closure table was successfully recomputed (not committed yet); all {} organizations processed", orgsTotal);
if (check) {
LOGGER.info("Reading from recomputed org closure table");
NativeQuery selectQuery = session.createNativeQuery("SELECT descendant_oid, ancestor_oid, val from " + CLOSURE_TABLE_NAME).addScalar("descendant_oid", StringType.INSTANCE).addScalar("ancestor_oid", StringType.INSTANCE).addScalar("val", IntegerType.INSTANCE);
List recomputedEntries = selectQuery.list();
LOGGER.info("{} entries read", recomputedEntries.size());
compareOrgClosureTables(existingEntries, recomputedEntries, rebuild, result);
} else {
result.recordSuccess();
}
}
use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.
the class TestLdap method test800BigLdapSearch.
@Test
public void test800BigLdapSearch() throws Exception {
// GIVEN
assertUsers(NUM_INITIAL_USERS + 1);
loadLdapEntries("a", NUM_LDAP_ENTRIES);
Task task = getTestTask();
task.setOwner(getUser(USER_ADMINISTRATOR_OID));
OperationResult result = task.getResult();
ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(RESOURCE_OPENDJ_OID, new QName(RESOURCE_OPENDJ_NAMESPACE, "inetOrgPerson"), prismContext);
final MutableInt count = new MutableInt(0);
ResultHandler<ShadowType> handler = new ResultHandler<ShadowType>() {
@Override
public boolean handle(PrismObject<ShadowType> shadow, OperationResult parentResult) {
count.increment();
display("Found", shadow);
return true;
}
};
// WHEN
when();
modelService.searchObjectsIterative(ShadowType.class, query, handler, null, task, result);
// THEN
then();
result.computeStatus();
TestUtil.assertSuccess(result);
// THEN
then();
assertEquals("Unexpected number of search results", NUM_LDAP_ENTRIES + 8, count.intValue());
assertUsers(NUM_INITIAL_USERS + 1);
}
use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.
the class TestLdap method assertOpenDjAccountShadows.
private void assertOpenDjAccountShadows(int expected, boolean raw, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(RESOURCE_OPENDJ_OID, new QName(RESOURCE_OPENDJ_NAMESPACE, "inetOrgPerson"), prismContext);
final MutableInt count = new MutableInt(0);
ResultHandler<ShadowType> handler = new ResultHandler<ShadowType>() {
@Override
public boolean handle(PrismObject<ShadowType> shadow, OperationResult parentResult) {
count.increment();
display("Found", shadow);
return true;
}
};
Collection<SelectorOptions<GetOperationOptions>> options = null;
if (raw) {
options = SelectorOptions.createCollection(GetOperationOptions.createRaw());
}
modelService.searchObjectsIterative(ShadowType.class, query, handler, options, task, result);
assertEquals("Unexpected number of search results (raw=" + raw + ")", expected, count.intValue());
}
use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.
the class SearchProducerWorker method run.
@Override
public void run() {
Log log = context.getLog();
try {
GetOperationOptionsBuilder optionsBuilder = context.getSchemaService().getOperationOptionsBuilder();
if (options.isRaw()) {
optionsBuilder = optionsBuilder.raw();
}
optionsBuilder = NinjaUtils.addIncludeOptionsForExport(optionsBuilder, type.getClassDefinition());
ResultHandler<?> handler = (object, parentResult) -> {
try {
queue.put(object.asObjectable());
} catch (InterruptedException ex) {
log.error("Couldn't queue object {}, reason: {}", ex, object, ex.getMessage());
}
return true;
};
RepositoryService repository = context.getRepository();
repository.searchObjectsIterative(type.getClassDefinition(), query, handler, optionsBuilder.build(), true, operation.getResult());
} catch (SchemaException ex) {
log.error("Unexpected exception, reason: {}", ex, ex.getMessage());
} catch (NinjaException ex) {
log.error(ex.getMessage(), ex);
} finally {
markDone();
if (isWorkersDone()) {
if (!operation.isFinished()) {
operation.producerFinish();
}
}
}
}
use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.
the class ResourceObjectReferenceResolver method resolve.
/**
* Resolves a {@link ResourceObjectReferenceType}.
*
* @param useRawDefinition If true, object class definition is used (instead of object type definition).
* This is to avoid endless recursion when resolving the base context for object type.
*/
@Nullable
PrismObject<ShadowType> resolve(@NotNull ProvisioningContext ctx, @NotNull ResourceObjectReferenceType resourceObjectReference, boolean useRawDefinition, @NotNull String desc, @NotNull OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
ObjectReferenceType shadowRef = resourceObjectReference.getShadowRef();
if (shadowRef != null && shadowRef.getOid() != null) {
if (resourceObjectReference.getResolutionFrequency() == null || resourceObjectReference.getResolutionFrequency() == ResourceObjectReferenceResolutionFrequencyType.ONCE) {
PrismObject<ShadowType> shadow = repositoryService.getObject(ShadowType.class, shadowRef.getOid(), null, result);
shadowsFacade.applyDefinition(shadow, ctx.getTask(), result);
return shadow;
}
} else if (resourceObjectReference.getResolutionFrequency() == ResourceObjectReferenceResolutionFrequencyType.NEVER) {
throw new ObjectNotFoundException("No shadowRef OID in " + desc + " and resolution frequency set to NEVER");
}
argCheck(resourceObjectReference.getObjectClass() != null, "No object class name in object reference in %s", desc);
QName objectClassName = QNameUtil.qualifyIfNeeded(resourceObjectReference.getObjectClass(), MidPointConstants.NS_RI);
ProvisioningContext subCtx = useRawDefinition ? ctx.spawnForObjectClassWithRawDefinition(objectClassName) : ctx.spawnForObjectClass(objectClassName);
subCtx.assertDefinition();
ObjectQuery refQuery = prismContext.getQueryConverter().createObjectQuery(ShadowType.class, resourceObjectReference.getFilter());
// No variables. At least not now. We expect that mostly constants will be used here.
VariablesMap variables = new VariablesMap();
ObjectQuery evaluatedRefQuery = ExpressionUtil.evaluateQueryExpressions(refQuery, variables, MiscSchemaUtil.getExpressionProfile(), expressionFactory, prismContext, desc, ctx.getTask(), result);
ObjectFilter baseFilter = ObjectQueryUtil.createResourceAndObjectClassFilter(ctx.getResource().getOid(), objectClassName, prismContext);
ObjectFilter filter = prismContext.queryFactory().createAnd(baseFilter, evaluatedRefQuery.getFilter());
ObjectQuery query = prismContext.queryFactory().createQuery(filter);
// TODO: implement "repo" search strategies, don't forget to apply definitions
Holder<PrismObject<ShadowType>> shadowHolder = new Holder<>();
ResultHandler<ShadowType> handler = (shadow, objResult) -> {
if (shadowHolder.getValue() != null) {
throw new IllegalStateException("More than one search results for " + desc);
}
shadowHolder.setValue(shadow);
return true;
};
shadowsFacade.searchObjectsIterative(subCtx, query, null, handler, result);
return shadowHolder.getValue();
}
Aggregations