use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.
the class SearchIterativeTest method test100SimpleIteration.
@Test
public void test100SimpleIteration() throws Exception {
OperationResult result = new OperationResult("test100SimpleIteration");
final List<PrismObject<UserType>> objects = new ArrayList<>();
ResultHandler handler = new ResultHandler() {
@Override
public boolean handle(PrismObject object, OperationResult parentResult) {
objects.add(object);
return true;
}
};
repositoryService.searchObjectsIterative(UserType.class, null, handler, null, true, result);
result.recomputeStatus();
assertTrue(result.isSuccess());
assertObjects(objects, COUNT);
}
use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.
the class TestRetirement method reconcileAllUsers.
private void reconcileAllUsers() throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
final Task task = createTask("reconcileAllUsers");
OperationResult result = task.getResult();
ResultHandler<UserType> handler = new ResultHandler<UserType>() {
@Override
public boolean handle(PrismObject<UserType> object, OperationResult parentResult) {
try {
display("reconciling " + object);
reconcileUser(object.getOid(), task, parentResult);
} catch (SchemaException | PolicyViolationException | ExpressionEvaluationException | ObjectNotFoundException | ObjectAlreadyExistsException | CommunicationException | ConfigurationException | SecurityViolationException e) {
throw new SystemException(e.getMessage(), e);
}
return true;
}
};
display("Reconciling all users");
modelService.searchObjectsIterative(UserType.class, null, handler, null, task, result);
}
use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.
the class AbstractLdapHierarchyTest method reconcileAllUsers.
protected void reconcileAllUsers() throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
final Task task = createTask("reconcileAllUsers");
OperationResult result = task.getResult();
ResultHandler<UserType> handler = new ResultHandler<UserType>() {
@Override
public boolean handle(PrismObject<UserType> object, OperationResult parentResult) {
try {
display("reconciling " + object);
reconcileUser(object.getOid(), task, parentResult);
} catch (SchemaException | PolicyViolationException | ExpressionEvaluationException | ObjectNotFoundException | ObjectAlreadyExistsException | CommunicationException | ConfigurationException | SecurityViolationException e) {
throw new SystemException(e.getMessage(), e);
}
return true;
}
};
display("Reconciling all users");
modelService.searchObjectsIterative(UserType.class, null, handler, null, task, result);
}
use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.
the class Construction method resolveTarget.
private ResourceType resolveTarget(String sourceDescription, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
// SearchFilterType filter = targetRef.getFilter();
ExpressionVariables variables = Utils.getDefaultExpressionVariables(getFocusOdo().getNewObject().asObjectable(), null, null, null);
if (assignmentPathVariables == null) {
assignmentPathVariables = LensUtil.computeAssignmentPathVariables(getAssignmentPath());
}
Utils.addAssignmentPathVariables(assignmentPathVariables, variables);
LOGGER.info("Expression variables for filter evaluation: {}", variables);
ObjectFilter origFilter = QueryConvertor.parseFilter(getConstructionType().getResourceRef().getFilter(), ResourceType.class, getPrismContext());
LOGGER.info("Orig filter {}", origFilter);
ObjectFilter evaluatedFilter = ExpressionUtil.evaluateFilterExpressions(origFilter, variables, getMappingFactory().getExpressionFactory(), getPrismContext(), " evaluating resource filter expression ", task, result);
LOGGER.info("evaluatedFilter filter {}", evaluatedFilter);
if (evaluatedFilter == null) {
throw new SchemaException("The OID is null and filter could not be evaluated in assignment targetRef in " + getSource());
}
final Collection<PrismObject<ResourceType>> results = new ArrayList<>();
ResultHandler<ResourceType> handler = (object, parentResult) -> {
LOGGER.info("Found object {}", object);
return results.add(object);
};
getObjectResolver().searchIterative(ResourceType.class, ObjectQuery.createObjectQuery(evaluatedFilter), null, handler, task, result);
if (org.apache.commons.collections.CollectionUtils.isEmpty(results)) {
throw new IllegalArgumentException("Got no target from repository, filter:" + evaluatedFilter + ", class:" + ResourceType.class + " in " + sourceDescription);
}
if (results.size() > 1) {
throw new IllegalArgumentException("Got more than one target from repository, filter:" + evaluatedFilter + ", class:" + ResourceType.class + " in " + sourceDescription);
}
PrismObject<ResourceType> target = results.iterator().next();
// assignmentType.getTargetRef().setOid(target.getOid());
return target.asObjectable();
}
use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.
the class ReconciliationTaskHandler method performShadowReconciliation.
// returns false in case of execution interruption
private boolean performShadowReconciliation(final PrismObject<ResourceType> resource, final ObjectClassComplexTypeDefinition objectclassDef, long startTimestamp, long endTimestamp, ReconciliationTaskResult reconResult, final Task task, OperationResult result) throws SchemaException {
boolean interrupted;
// find accounts
LOGGER.trace("Shadow reconciliation starting for {}, {} -> {}", new Object[] { resource, startTimestamp, endTimestamp });
OperationResult opResult = result.createSubresult(OperationConstants.RECONCILIATION + ".shadowReconciliation");
ObjectQuery query = QueryBuilder.queryFor(ShadowType.class, prismContext).block().item(ShadowType.F_FULL_SYNCHRONIZATION_TIMESTAMP).le(XmlTypeConverter.createXMLGregorianCalendar(startTimestamp)).or().item(ShadowType.F_FULL_SYNCHRONIZATION_TIMESTAMP).isNull().endBlock().and().item(ShadowType.F_RESOURCE_REF).ref(ObjectTypeUtil.createObjectRef(resource).asReferenceValue()).and().item(ShadowType.F_OBJECT_CLASS).eq(objectclassDef.getTypeName()).build();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Shadow recon query:\n{}", query.debugDump());
}
long started = System.currentTimeMillis();
final Holder<Long> countHolder = new Holder<Long>(0L);
ResultHandler<ShadowType> handler = new ResultHandler<ShadowType>() {
@Override
public boolean handle(PrismObject<ShadowType> shadow, OperationResult parentResult) {
if ((objectclassDef instanceof RefinedObjectClassDefinition) && !((RefinedObjectClassDefinition) objectclassDef).matches(shadow.asObjectable())) {
return true;
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Shadow reconciliation of {}, fullSynchronizationTimestamp={}", shadow, shadow.asObjectable().getFullSynchronizationTimestamp());
}
long started = System.currentTimeMillis();
PrismObject<ShadowType> resourceShadow = null;
try {
task.recordIterativeOperationStart(shadow.asObjectable());
resourceShadow = reconcileShadow(shadow, resource, task);
task.recordIterativeOperationEnd(shadow.asObjectable(), started, null);
} catch (Throwable t) {
task.recordIterativeOperationEnd(shadow.asObjectable(), started, t);
throw t;
}
if (ShadowUtil.isProtected(resourceShadow)) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Skipping recording counter for {} because it is protected", shadow);
}
return task.canRun();
}
countHolder.setValue(countHolder.getValue() + 1);
// reconcileShadow writes to its own dummy OperationResult, so we do the same here
incrementAndRecordProgress(task, new OperationResult("dummy"));
return task.canRun();
}
};
repositoryService.searchObjectsIterative(ShadowType.class, query, handler, null, true, opResult);
interrupted = !task.canRun();
// for each try the operation again
opResult.computeStatus();
LOGGER.trace("Shadow reconciliation finished, processed {} shadows for {}, result: {}", new Object[] { countHolder.getValue(), resource, opResult.getStatus() });
reconResult.setShadowReconCount(countHolder.getValue());
result.createSubresult(OperationConstants.RECONCILIATION + ".shadowReconciliation.statistics").recordStatus(OperationResultStatus.SUCCESS, "Processed " + countHolder.getValue() + " shadow(s) in " + (System.currentTimeMillis() - started) + " ms." + (interrupted ? " Was interrupted during processing." : ""));
return !interrupted;
}
Aggregations