use of com.evolveum.midpoint.schema.SearchResultMetadata in project midpoint by Evolveum.
the class AbstractAdLdapMultidomainTest method test152SeachFirst2Accounts.
/**
* This is in one block.
*/
@Test
public void test152SeachFirst2Accounts() throws Exception {
final String TEST_NAME = "test152SeachFirst2Accounts";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass(), prismContext);
ObjectPaging paging = ObjectPaging.createEmptyPaging();
paging.setMaxSize(2);
query.setPaging(paging);
SearchResultList<PrismObject<ShadowType>> searchResultList = doSearch(TEST_NAME, query, 2, task, result);
// assertConnectorOperationIncrement(1);
assertConnectorSimulatedPagingSearchIncrement(0);
SearchResultMetadata metadata = searchResultList.getMetadata();
if (metadata != null) {
assertFalse(metadata.isPartialResults());
}
// assertLdapConnectorInstances(2);
}
use of com.evolveum.midpoint.schema.SearchResultMetadata in project midpoint by Evolveum.
the class AbstractAdLdapMultidomainTest method test101SeachJackByDn.
/**
* MID-3730
*/
@Test
public void test101SeachJackByDn() throws Exception {
final String TEST_NAME = "test101SeachJackByDn";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
String jackDn = toAccountDn(ACCOUNT_JACK_SAM_ACCOUNT_NAME, ACCOUNT_JACK_FULL_NAME);
ObjectQuery query = createAccountShadowQueryByAttribute("dn", jackDn, resource);
rememberConnectorOperationCount();
rememberConnectorSimulatedPagingSearchCount();
// WHEN
TestUtil.displayWhen(TEST_NAME);
SearchResultList<PrismObject<ShadowType>> shadows = modelService.searchObjects(ShadowType.class, query, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
assertEquals("Unexpected search result: " + shadows, 1, shadows.size());
PrismObject<ShadowType> shadow = shadows.get(0);
display("Shadow", shadow);
assertAccountShadow(shadow, jackDn);
// assertConnectorOperationIncrement(2);
assertConnectorSimulatedPagingSearchIncrement(0);
SearchResultMetadata metadata = shadows.getMetadata();
if (metadata != null) {
assertFalse(metadata.isPartialResults());
}
assertLdapConnectorInstances(1);
}
use of com.evolveum.midpoint.schema.SearchResultMetadata in project midpoint by Evolveum.
the class ResourceObjectConverter method searchResourceObjects.
public SearchResultMetadata searchResourceObjects(final ProvisioningContext ctx, final ResultHandler<ShadowType> resultHandler, ObjectQuery query, final boolean fetchAssociations, final OperationResult parentResult) throws SchemaException, CommunicationException, ObjectNotFoundException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
LOGGER.trace("Searching resource objects, query: {}", query);
RefinedObjectClassDefinition objectClassDef = ctx.getObjectClassDefinition();
AttributesToReturn attributesToReturn = ProvisioningUtil.createAttributesToReturn(ctx);
SearchHierarchyConstraints searchHierarchyConstraints = null;
ResourceObjectReferenceType baseContextRef = objectClassDef.getBaseContext();
if (baseContextRef != null) {
PrismObject<ShadowType> baseContextShadow = resourceObjectReferenceResolver.resolve(ctx, baseContextRef, null, "base context specification in " + objectClassDef, parentResult);
if (baseContextShadow == null) {
throw new ObjectNotFoundException("No base context defined by " + baseContextRef + " in base context specification in " + objectClassDef);
}
RefinedObjectClassDefinition baseContextObjectClassDefinition = ctx.getRefinedSchema().determineCompositeObjectClassDefinition(baseContextShadow);
ResourceObjectIdentification baseContextIdentification = ShadowUtil.getResourceObjectIdentification(baseContextShadow, baseContextObjectClassDefinition);
searchHierarchyConstraints = new SearchHierarchyConstraints(baseContextIdentification, null);
}
if (InternalsConfig.consistencyChecks && query != null && query.getFilter() != null) {
query.getFilter().checkConsistence(true);
}
ConnectorInstance connector = ctx.getConnector(ReadCapabilityType.class, parentResult);
SearchResultMetadata metadata = null;
try {
metadata = connector.search(objectClassDef, query, (shadow) -> {
// in order to utilize the cache right from the beginning...
RepositoryCache.enter();
try {
try {
shadow = postProcessResourceObjectRead(ctx, shadow, fetchAssociations, parentResult);
} catch (SchemaException | CommunicationException | ConfigurationException | SecurityViolationException | ObjectNotFoundException | ExpressionEvaluationException e) {
throw new TunnelException(e);
}
return resultHandler.handle(shadow);
} finally {
RepositoryCache.exit();
}
}, attributesToReturn, objectClassDef.getPagedSearches(), searchHierarchyConstraints, ctx, parentResult);
} catch (GenericFrameworkException e) {
parentResult.recordFatalError("Generic error in the connector: " + e.getMessage(), e);
throw new SystemException("Generic error in the connector: " + e.getMessage(), e);
} catch (CommunicationException ex) {
parentResult.recordFatalError("Error communicating with the connector " + connector + ": " + ex.getMessage(), ex);
throw new CommunicationException("Error communicating with the connector " + connector + ": " + ex.getMessage(), ex);
} catch (SecurityViolationException ex) {
parentResult.recordFatalError("Security violation communicating with the connector " + connector + ": " + ex.getMessage(), ex);
throw new SecurityViolationException("Security violation communicating with the connector " + connector + ": " + ex.getMessage(), ex);
} catch (TunnelException e) {
Throwable cause = e.getCause();
if (cause instanceof SchemaException) {
throw (SchemaException) cause;
} else if (cause instanceof CommunicationException) {
throw (CommunicationException) cause;
} else if (cause instanceof ObjectNotFoundException) {
throw (ObjectNotFoundException) cause;
} else if (cause instanceof ConfigurationException) {
throw (ConfigurationException) cause;
} else if (cause instanceof SecurityViolationException) {
throw (SecurityViolationException) cause;
} else if (cause instanceof ExpressionEvaluationException) {
throw (ExpressionEvaluationException) cause;
} else if (cause instanceof GenericFrameworkException) {
throw new GenericConnectorException(cause.getMessage(), cause);
} else {
throw new SystemException(cause.getMessage(), cause);
}
}
computeResultStatus(parentResult);
LOGGER.trace("Searching resource objects done: {}", parentResult.getStatus());
return metadata;
}
use of com.evolveum.midpoint.schema.SearchResultMetadata in project midpoint by Evolveum.
the class SqaleAuditSearchIterativeTest method test111SearchIterativeWithLastPageNotFull.
@Test
public void test111SearchIterativeWithLastPageNotFull() throws Exception {
OperationResult operationResult = createOperationResult();
SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
pm.clearGlobalPerformanceInformation();
given("total result count not multiple of the page size");
sqaleAuditService.repositoryConfiguration().setIterativeSearchByPagingBatchSize(47);
when("calling search iterative with null query");
SearchResultMetadata metadata = searchObjectsIterative(null, operationResult);
then("result metadata is not null and reports the handled objects");
assertThatOperationResult(operationResult).isSuccess();
assertThat(metadata).isNotNull();
assertThat(metadata.getApproxNumberOfAllResults()).isEqualTo(testHandler.processedCount());
assertThat(metadata.isPartialResults()).isFalse();
assertThat(metadata.getPagingCookie()).isNotNull();
and("search operations were called");
assertOperationRecordedCount(AUDIT_OP_PREFIX + AuditService.OP_SEARCH_OBJECTS_ITERATIVE, 1);
assertTypicalPageOperationCount(metadata);
and("all objects of the specified type were processed");
assertThat(testHandler.processedCount()).isEqualTo(count(aer));
}
use of com.evolveum.midpoint.schema.SearchResultMetadata in project midpoint by Evolveum.
the class SqaleRepoSearchIterativeTest method test111SearchIterativeWithLastPageNotFull.
@Test
public void test111SearchIterativeWithLastPageNotFull() throws Exception {
OperationResult operationResult = createOperationResult();
SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
pm.clearGlobalPerformanceInformation();
given("total result count not multiple of the page size");
long totalCount = count(QObject.CLASS);
int iterativePageSize = 47;
repositoryConfiguration.setIterativeSearchByPagingBatchSize(iterativePageSize);
assertThat(totalCount % repositoryConfiguration.getIterativeSearchByPagingBatchSize()).isNotZero();
queryRecorder.clearBufferAndStartRecording();
when("calling search iterative with null query");
SearchResultMetadata metadata = searchObjectsIterative(null, operationResult);
then("result metadata is not null and reports the handled objects");
assertThatOperationResult(operationResult).isSuccess();
assertThat(metadata).isNotNull();
assertThat(metadata.getApproxNumberOfAllResults()).isEqualTo(testHandler.getCounter());
assertThat(metadata.isPartialResults()).isFalse();
// page cookie is not null and it's OID in UUID format
assertThat(UUID.fromString(metadata.getPagingCookie())).isNotNull();
and("search operations were called");
assertOperationRecordedCount(REPO_OP_PREFIX + RepositoryService.OP_SEARCH_OBJECTS_ITERATIVE, 1);
assertTypicalPageOperationCount(metadata);
and("all objects of the specified type were processed");
assertThat(testHandler.getCounter()).isEqualTo(count(QUser.class));
and("last iteration query has proper conditions");
List<SqlRecorder.QueryEntry> iterativeSelects = queryRecorder.getQueryBuffer().stream().filter(e -> e.sql.contains("order by u.oid asc")).collect(Collectors.toList());
// +1 for the last page
assertThat(iterativeSelects).hasSize((int) totalCount / iterativePageSize + 1);
SqlRecorder.QueryEntry lastEntry = iterativeSelects.get(iterativeSelects.size() - 1);
// we want to be sure no accidental filter accumulation happens
assertThat(lastEntry.sql).contains("where u.oid > ?\norder by u.oid asc");
}
Aggregations