Search in sources :

Example 66 with SearchResultMetadata

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);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) SearchResultMetadata(com.evolveum.midpoint.schema.SearchResultMetadata) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Example 67 with SearchResultMetadata

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);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) SearchResultMetadata(com.evolveum.midpoint.schema.SearchResultMetadata) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Example 68 with SearchResultMetadata

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;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) ActivationCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType) Autowired(org.springframework.beans.factory.annotation.Autowired) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) InternalsConfig(com.evolveum.midpoint.schema.internals.InternalsConfig) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) com.evolveum.midpoint.common.refinery(com.evolveum.midpoint.common.refinery) AsynchronousOperationReturnValue(com.evolveum.midpoint.schema.result.AsynchronousOperationReturnValue) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ResourceTypeUtil(com.evolveum.midpoint.schema.util.ResourceTypeUtil) MatchingRuleRegistry(com.evolveum.midpoint.prism.match.MatchingRuleRegistry) AsynchronousOperationQueryable(com.evolveum.midpoint.schema.result.AsynchronousOperationQueryable) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) DeleteCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.DeleteCapabilityType) ReadCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ReadCapabilityType) UpdateCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.UpdateCapabilityType) Entry(java.util.Map.Entry) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) SearchResultMetadata(com.evolveum.midpoint.schema.SearchResultMetadata) QName(javax.xml.namespace.QName) NotNull(org.jetbrains.annotations.NotNull) Clock(com.evolveum.midpoint.common.Clock) Validate(org.apache.commons.lang.Validate) CreateCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CreateCapabilityType) java.util(java.util) com.evolveum.midpoint.util(com.evolveum.midpoint.util) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Trace(com.evolveum.midpoint.util.logging.Trace) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) GenericConnectorException(com.evolveum.midpoint.provisioning.api.GenericConnectorException) RepositoryCache(com.evolveum.midpoint.repo.cache.RepositoryCache) JavaTypeConverter(com.evolveum.midpoint.prism.util.JavaTypeConverter) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) SchemaDebugUtil(com.evolveum.midpoint.schema.util.SchemaDebugUtil) CapabilityUtil(com.evolveum.midpoint.schema.CapabilityUtil) AddRemoveAttributeValuesCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.AddRemoveAttributeValuesCapabilityType) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) PrismUtil(com.evolveum.midpoint.prism.util.PrismUtil) LiveSyncCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.LiveSyncCapabilityType) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) QueryBuilder(com.evolveum.midpoint.prism.query.builder.QueryBuilder) MatchingRule(com.evolveum.midpoint.prism.match.MatchingRule) Component(org.springframework.stereotype.Component) com.evolveum.midpoint.provisioning.ucf.api(com.evolveum.midpoint.provisioning.ucf.api) com.evolveum.midpoint.schema.processor(com.evolveum.midpoint.schema.processor) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult) ActivationStatusCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationStatusCapabilityType) ProvisioningUtil(com.evolveum.midpoint.provisioning.util.ProvisioningUtil) ShadowUtil(com.evolveum.midpoint.schema.util.ShadowUtil) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ActivationLockoutStatusCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationLockoutStatusCapabilityType) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) SearchResultMetadata(com.evolveum.midpoint.schema.SearchResultMetadata) GenericConnectorException(com.evolveum.midpoint.provisioning.api.GenericConnectorException)

Example 69 with SearchResultMetadata

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));
}
Also used : SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) SearchResultMetadata(com.evolveum.midpoint.schema.SearchResultMetadata) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)

Example 70 with SearchResultMetadata

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");
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JdbcSession(com.evolveum.midpoint.repo.sqlbase.JdbcSession) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) AfterMethod(org.testng.annotations.AfterMethod) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest) SqlRecorder(com.evolveum.midpoint.repo.sqlbase.querydsl.SqlRecorder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) QUser(com.evolveum.midpoint.repo.sqale.qmodel.focus.QUser) QObject(com.evolveum.midpoint.repo.sqale.qmodel.object.QObject) Predicate(java.util.function.Predicate) BeforeClass(org.testng.annotations.BeforeClass) BeforeMethod(org.testng.annotations.BeforeMethod) UUID(java.util.UUID) PrismObject(com.evolveum.midpoint.prism.PrismObject) Collectors(java.util.stream.Collectors) SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) List(java.util.List) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) SearchResultMetadata(com.evolveum.midpoint.schema.SearchResultMetadata) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) SqaleRepositoryService(com.evolveum.midpoint.repo.sqale.SqaleRepositoryService) QUser(com.evolveum.midpoint.repo.sqale.qmodel.focus.QUser) SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) SearchResultMetadata(com.evolveum.midpoint.schema.SearchResultMetadata) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SqlRecorder(com.evolveum.midpoint.repo.sqlbase.querydsl.SqlRecorder) Test(org.testng.annotations.Test) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)

Aggregations

SearchResultMetadata (com.evolveum.midpoint.schema.SearchResultMetadata)84 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)83 Test (org.testng.annotations.Test)80 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)76 PrismObject (com.evolveum.midpoint.prism.PrismObject)70 Task (com.evolveum.midpoint.task.api.Task)67 ObjectPaging (com.evolveum.midpoint.prism.query.ObjectPaging)35 AbstractAdLdapTest (com.evolveum.midpoint.testing.conntest.ad.AbstractAdLdapTest)19 SqaleRepoBaseTest (com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)13 SqlPerformanceMonitorImpl (com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl)13 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)11 AbstractIntegrationTest (com.evolveum.midpoint.test.AbstractIntegrationTest)9 AbstractLdapSynchronizationTest (com.evolveum.midpoint.testing.conntest.AbstractLdapSynchronizationTest)8 QUser (com.evolveum.midpoint.repo.sqale.qmodel.focus.QUser)5 JdbcSession (com.evolveum.midpoint.repo.sqlbase.JdbcSession)3 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)3 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3