use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.
the class PageAccounts method exportPerformed.
private void exportPerformed(AjaxRequestTarget target) {
if (resourceModel.getObject() == null) {
warn(getString("pageAccounts.message.resourceNotSelected"));
refreshEverything(target);
return;
}
String fileName = "accounts-" + WebComponentUtil.formatDate("yyyy-MM-dd-HH-mm-ss", new Date()) + ".xml";
OperationResult result = new OperationResult(OPERATION_EXPORT);
Writer writer = null;
try {
Task task = createSimpleTask(OPERATION_EXPORT);
writer = createWriter(fileName);
writeHeader(writer);
final Writer handlerWriter = writer;
ResultHandler handler = new AbstractSummarizingResultHandler() {
@Override
protected boolean handleObject(PrismObject object, OperationResult parentResult) {
OperationResult result = parentResult.createMinorSubresult(OPERATION_EXPORT_ACCOUNT);
try {
String xml = getPrismContext().serializeObjectToString(object, PrismContext.LANG_XML);
handlerWriter.write(xml);
result.computeStatus();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't serialize account", ex);
result.recordFatalError("Couldn't serialize account.", ex);
return false;
}
return true;
}
};
try {
ObjectQuery query = ObjectQuery.createObjectQuery(createResourceAndQueryFilter());
getModelService().searchObjectsIterative(ShadowType.class, query, handler, SelectorOptions.createCollection(GetOperationOptions.createRaw()), task, result);
} finally {
writeFooter(writer);
}
result.recomputeStatus();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't export accounts", ex);
error(getString("PageAccounts.exportException", ex.getMessage()));
} finally {
IOUtils.closeQuietly(writer);
}
filesModel.reset();
success(getString("PageAccounts.message.success.export", fileName));
target.add(getFeedbackPanel(), get(createComponentPath(ID_FORM_ACCOUNT, ID_FILES_CONTAINER)));
}
use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.
the class AbstractSearchExpressionEvaluator method executeSearchAttempt.
private <O extends ObjectType> List<V> executeSearchAttempt(final List<PrismObject> rawResult, Class<O> targetTypeClass, final QName targetTypeQName, ObjectQuery query, boolean searchOnResource, boolean tryAlsoRepository, final List<ItemDelta<V, D>> additionalAttributeDeltas, final ExpressionEvaluationContext params, String contextDescription, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
final List<V> list = new ArrayList<V>();
Collection<SelectorOptions<GetOperationOptions>> options = new ArrayList<>();
if (!searchOnResource) {
options.add(SelectorOptions.create(GetOperationOptions.createNoFetch()));
}
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));
return true;
}
};
try {
objectResolver.searchIterative(targetTypeClass, query, options, handler, task, result);
} catch (IllegalStateException e) {
// this comes from checkConsistence methods
throw new IllegalStateException(e.getMessage() + " in " + contextDescription, e);
} catch (SchemaException e) {
throw new SchemaException(e.getMessage() + " in " + contextDescription, e);
} catch (SystemException e) {
throw new SystemException(e.getMessage() + " in " + contextDescription, e);
} catch (CommunicationException | ConfigurationException | SecurityViolationException e) {
if (searchOnResource && tryAlsoRepository) {
options = SelectorOptions.createCollection(GetOperationOptions.createNoFetch());
try {
objectResolver.searchIterative(targetTypeClass, query, options, handler, task, result);
} catch (SchemaException e1) {
throw new SchemaException(e1.getMessage() + " in " + contextDescription, e1);
} catch (CommunicationException | ConfigurationException | SecurityViolationException e1) {
// shadow for group doesn't exist? (MID-2107)
throw new ExpressionEvaluationException("Unexpected expression exception " + e + ": " + e.getMessage(), e);
}
} else {
throw new ExpressionEvaluationException("Unexpected expression exception " + e + ": " + e.getMessage(), e);
}
} catch (ObjectNotFoundException e) {
throw e;
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Assignment expression resulted in {} objects, using query:\n{}", list.size(), query.debugDump());
}
return list;
}
use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.
the class AddGetObjectTest method test.
// @Test(enabled = false)
// public void deltaOperationSerializationPerformanceTest() throws Exception {
// List<PrismObject<? extends Objectable>> elements =
// prismContext.processorFor(new File(FOLDER_BASIC, "objects.xml")).parseObjects();
//
// //get user from objects.xml
// ObjectDelta delta = ObjectDelta.createAddDelta(elements.get(0));
//
// final int COUNT = 10000;
// //first conversion option
// System.out.println(DeltaConvertor.toObjectDeltaTypeXml(delta));
// //second conversion option
// //System.out.println("\n" + toRepo(DeltaConvertor.toObjectDeltaType(delta), prismContext));
//
// long time = System.currentTimeMillis();
// for (int i = 0; i < COUNT; i++) {
// String xml = DeltaConvertor.toObjectDeltaTypeXml(delta);
// }
// time = System.currentTimeMillis() - time;
// System.out.println(">>> " + time);
//
// time = System.currentTimeMillis();
// for (int i = 0; i < COUNT; i++) {
// ObjectDeltaType type = DeltaConvertor.toObjectDeltaType(delta);
// String xml = toRepo(type, prismContext);
// }
// time = System.currentTimeMillis() - time;
// System.out.println(">>> " + time);
// }
@Test
public void test() throws Exception {
OperationResult result = new OperationResult("asdf");
final List<PrismObject> objects = new ArrayList<PrismObject>();
ResultHandler<ObjectType> handler = new ResultHandler<ObjectType>() {
@Override
public boolean handle(PrismObject<ObjectType> object, OperationResult parentResult) {
objects.add(object);
return true;
}
};
repositoryService.searchObjectsIterative(ObjectType.class, null, handler, null, false, result);
AssertJUnit.assertTrue(!objects.isEmpty());
}
use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.
the class TestRetirement method reconcileAllOrgs.
private void reconcileAllOrgs() throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
final Task task = createTask("reconcileAllOrgs");
OperationResult result = task.getResult();
ResultHandler<OrgType> handler = new ResultHandler<OrgType>() {
@Override
public boolean handle(PrismObject<OrgType> object, OperationResult parentResult) {
try {
display("reconciling " + object);
reconcileOrg(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 orgs");
modelService.searchObjectsIterative(OrgType.class, null, handler, null, task, result);
}
use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.
the class TestSanity method test016ProvisioningSearchAccountsIterative.
@Test
public void test016ProvisioningSearchAccountsIterative() throws Exception {
TestUtil.displayTestTile("test016ProvisioningSearchAccountsIterative");
// GIVEN
OperationResult result = new OperationResult(TestSanity.class.getName() + ".test016ProvisioningSearchAccountsIterative");
RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resourceTypeOpenDjrepo, prismContext);
final RefinedObjectClassDefinition refinedAccountDefinition = refinedSchema.getDefaultRefinedDefinition(ShadowKindType.ACCOUNT);
QName objectClass = refinedAccountDefinition.getObjectClassDefinition().getTypeName();
ObjectQuery q = ObjectQueryUtil.createResourceAndObjectClassQuery(resourceTypeOpenDjrepo.getOid(), objectClass, prismContext);
// ObjectQuery q = QueryConvertor.createObjectQuery(ResourceObjectShadowType.class, query, prismContext);
final Collection<ObjectType> objects = new HashSet<ObjectType>();
final MatchingRule caseIgnoreMatchingRule = matchingRuleRegistry.getMatchingRule(StringIgnoreCaseMatchingRule.NAME, DOMUtil.XSD_STRING);
ResultHandler handler = new ResultHandler<ObjectType>() {
@Override
public boolean handle(PrismObject<ObjectType> prismObject, OperationResult parentResult) {
ObjectType objectType = prismObject.asObjectable();
objects.add(objectType);
display("Found object", objectType);
assertTrue(objectType instanceof ShadowType);
ShadowType shadow = (ShadowType) objectType;
assertNotNull(shadow.getOid());
assertNotNull(shadow.getName());
assertEquals(RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS, shadow.getObjectClass());
assertEquals(RESOURCE_OPENDJ_OID, shadow.getResourceRef().getOid());
String icfUid = getAttributeValue(shadow, getOpenDjPrimaryIdentifierQName());
assertNotNull("No ICF UID", icfUid);
String icfName = getNormalizedAttributeValue(shadow, refinedAccountDefinition, getOpenDjSecondaryIdentifierQName());
assertNotNull("No ICF NAME", icfName);
try {
PrismAsserts.assertEquals("Wrong shadow name", caseIgnoreMatchingRule, shadow.getName().getOrig(), icfName);
} catch (SchemaException e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
assertNotNull("Missing LDAP uid", getAttributeValue(shadow, new QName(ResourceTypeUtil.getResourceNamespace(resourceTypeOpenDjrepo), "uid")));
assertNotNull("Missing LDAP cn", getAttributeValue(shadow, new QName(ResourceTypeUtil.getResourceNamespace(resourceTypeOpenDjrepo), "cn")));
assertNotNull("Missing LDAP sn", getAttributeValue(shadow, new QName(ResourceTypeUtil.getResourceNamespace(resourceTypeOpenDjrepo), "sn")));
assertNotNull("Missing activation", shadow.getActivation());
assertNotNull("Missing activation status", shadow.getActivation().getAdministrativeStatus());
return true;
}
};
// WHEN
provisioningService.searchObjectsIterative(ShadowType.class, q, null, handler, null, result);
// THEN
display("Count", objects.size());
}
Aggregations