Search in sources :

Example 36 with SearchResultList

use of com.evolveum.midpoint.schema.SearchResultList in project midpoint by Evolveum.

the class TestAdHocCertification method test030ModifyIndigo.

@Test
public void test030ModifyIndigo() throws Exception {
    // GIVEN
    Task task = getTestTask();
    task.setOwner(userAdministrator.asPrismObject());
    OperationResult result = task.getResult();
    // WHEN
    when();
    @SuppressWarnings({ "unchecked", "raw" }) ObjectDelta<UserType> delta = prismContext.deltaFor(UserType.class).item(UserType.F_DESCRIPTION).replace("new description").item(UserType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS).replace(ActivationStatusType.DISABLED).asObjectDelta(USER_INDIGO_OID);
    executeChanges(delta, null, task, result);
    // THEN
    then();
    result.computeStatus();
    TestUtil.assertSuccess(result);
    SearchResultList<PrismObject<AccessCertificationCampaignType>> campaigns = getAllCampaigns(result);
    assertEquals("Wrong # of campaigns", 2, campaigns.size());
    AccessCertificationCampaignType campaign = campaigns.stream().filter(c -> MODIFICATION_CERT_DEF_OID.equals(c.asObjectable().getDefinitionRef().getOid())).findFirst().orElseThrow(() -> new AssertionError("No modification-triggered campaign")).asObjectable();
    campaign = getCampaignWithCases(campaign.getOid());
    display("campaign", campaign);
    // beware, maybe not all details would match (in the future) - then adapt this test
    assertSanityAfterCampaignStart(campaign, modificationCertificationDefinition, 1);
    // no cases, no problems
    assertPercentCompleteAll(campaign, 0, 0, 0);
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) PrismObject(com.evolveum.midpoint.prism.PrismObject) DebugUtil(com.evolveum.midpoint.util.DebugUtil) Task(com.evolveum.midpoint.task.api.Task) AndFilter(com.evolveum.midpoint.prism.query.AndFilter) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) File(java.io.File) InOidFilter(com.evolveum.midpoint.prism.query.InOidFilter) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) PrismContext(com.evolveum.midpoint.prism.PrismContext) ContextConfiguration(org.springframework.test.context.ContextConfiguration) TestUtil(com.evolveum.midpoint.test.util.TestUtil) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 37 with SearchResultList

use of com.evolveum.midpoint.schema.SearchResultList in project midpoint by Evolveum.

the class BasePrimaryChangeAspect method resolveReferenceFromFilter.

private <O extends ObjectType, F extends ObjectType> List<ObjectReferenceType> resolveReferenceFromFilter(Class<O> clazz, SearchFilterType filter, String sourceDescription, LensContext<F> lensContext, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
    ModelExpressionThreadLocalHolder.pushExpressionEnvironment(new ExpressionEnvironment.ExpressionEnvironmentBuilder<F, PrismValue, ItemDefinition<?>>().lensContext(lensContext).currentResult(result).currentTask(task).build());
    try {
        PrismObject<SystemConfigurationType> systemConfiguration = systemObjectCache.getSystemConfiguration(result);
        VariablesMap variables = ModelImplUtils.getDefaultVariablesMap(getFocusObjectable(lensContext), null, null, systemConfiguration.asObjectable(), prismContext);
        ObjectFilter origFilter = prismContext.getQueryConverter().parseFilter(filter, clazz);
        ObjectFilter evaluatedFilter = ExpressionUtil.evaluateFilterExpressions(origFilter, variables, MiscSchemaUtil.getExpressionProfile(), mappingFactory.getExpressionFactory(), prismContext, " evaluating approverRef filter expression ", task, result);
        if (evaluatedFilter == null) {
            throw new SchemaException("Filter could not be evaluated in approverRef in " + sourceDescription + "; original filter = " + origFilter);
        }
        SearchResultList<PrismObject<O>> targets = repositoryService.searchObjects(clazz, prismContext.queryFactory().createQuery(evaluatedFilter), null, result);
        return targets.stream().map(object -> ObjectTypeUtil.createObjectRef(object, prismContext)).collect(Collectors.toList());
    } finally {
        ModelExpressionThreadLocalHolder.popExpressionEnvironment();
    }
}
Also used : ExpressionEnvironment(com.evolveum.midpoint.model.common.expression.ExpressionEnvironment) ConfigurationHelper(com.evolveum.midpoint.wf.impl.processors.ConfigurationHelper) ModelHelper(com.evolveum.midpoint.wf.impl.processors.ModelHelper) java.util(java.util) RelationResolver(com.evolveum.midpoint.wf.impl.processes.itemApproval.RelationResolver) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) Trace(com.evolveum.midpoint.util.logging.Trace) ModelExpressionThreadLocalHolder(com.evolveum.midpoint.model.common.expression.ModelExpressionThreadLocalHolder) DebugUtil(com.evolveum.midpoint.util.DebugUtil) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ModelImplUtils(com.evolveum.midpoint.model.impl.util.ModelImplUtils) ExpressionEnvironment(com.evolveum.midpoint.model.common.expression.ExpressionEnvironment) ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) MappingFactory(com.evolveum.midpoint.model.common.mapping.MappingFactory) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) ApprovalSchemaHelper(com.evolveum.midpoint.wf.impl.processes.itemApproval.ApprovalSchemaHelper) RelationRegistry(com.evolveum.midpoint.schema.RelationRegistry) MiscSchemaUtil(com.evolveum.midpoint.schema.util.MiscSchemaUtil) Qualifier(org.springframework.beans.factory.annotation.Qualifier) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) BeanNameAware(org.springframework.beans.factory.BeanNameAware) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) ReferenceResolver(com.evolveum.midpoint.wf.impl.processes.itemApproval.ReferenceResolver) S_AtomicFilterExit(com.evolveum.midpoint.prism.query.builder.S_AtomicFilterExit) Task(com.evolveum.midpoint.task.api.Task) Collectors(java.util.stream.Collectors) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) PrimaryChangeProcessor(com.evolveum.midpoint.wf.impl.processors.primary.PrimaryChangeProcessor) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) SystemObjectCache(com.evolveum.midpoint.model.common.SystemObjectCache) ExpressionUtil(com.evolveum.midpoint.repo.common.expression.ExpressionUtil) PostConstruct(javax.annotation.PostConstruct) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) QName(javax.xml.namespace.QName) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap)

Example 38 with SearchResultList

use of com.evolveum.midpoint.schema.SearchResultList in project midpoint by Evolveum.

the class AuditSearchTest method test520SearchByChangedItemOrAnotherChangedItem.

@Test
public void test520SearchByChangedItemOrAnotherChangedItem() throws SchemaException {
    // result should be similar to changedItem.eq(multiple values)
    when("searching audit filtered by changed item OR another changed item");
    SearchResultList<AuditEventRecordType> result = searchObjects(prismContext.queryFor(AuditEventRecordType.class).item(AuditEventRecordType.F_CHANGED_ITEM).eq(new ItemPathType(UserType.F_ADDITIONAL_NAME)).or().item(AuditEventRecordType.F_CHANGED_ITEM).eq(new ItemPathType(UserType.F_FAMILY_NAME)).build(), SelectorOptions.create(GetOperationOptions.createDistinct()));
    then("only audit events having either of (and/or) specified changed items are returned");
    assertThat(result).hasSize(2);
    assertThat(result).extracting(aer -> aer.getParameter()).containsExactlyInAnyOrder("1", "2");
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) Arrays(java.util.Arrays) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) AuditEventStage(com.evolveum.midpoint.audit.api.AuditEventStage) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) com.evolveum.midpoint.xml.ns._public.common.audit_3(com.evolveum.midpoint.xml.ns._public.common.audit_3) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) MiscUtil(com.evolveum.midpoint.util.MiscUtil) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) PrismObject(com.evolveum.midpoint.prism.PrismObject) NullTaskImpl(com.evolveum.midpoint.task.api.test.NullTaskImpl) CHANNEL_REST_URI(com.evolveum.midpoint.schema.constants.SchemaConstants.CHANNEL_REST_URI) Collectors(java.util.stream.Collectors) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) List(java.util.List) AuditEventType(com.evolveum.midpoint.audit.api.AuditEventType) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) ContextConfiguration(org.springframework.test.context.ContextConfiguration) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) Comparator(java.util.Comparator) NotNull(org.jetbrains.annotations.NotNull) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) Test(org.testng.annotations.Test)

Example 39 with SearchResultList

use of com.evolveum.midpoint.schema.SearchResultList in project midpoint by Evolveum.

the class AuditSearchTest method test270SearchByChangedItemsMultipleValues.

@Test
public void test270SearchByChangedItemsMultipleValues() throws SchemaException {
    // this tests multiple values for JOIN path
    when("searching audit by changed items equal to multiple values");
    SearchResultList<AuditEventRecordType> result = searchObjects(prismContext.queryFor(AuditEventRecordType.class).item(AuditEventRecordType.F_CHANGED_ITEM).eq(new ItemPathType(UserType.F_ADDITIONAL_NAME), new ItemPathType(UserType.F_FAMILY_NAME)).build(), SelectorOptions.create(GetOperationOptions.createDistinct()));
    then("audit events with changed items equal to any of the specified values are returned");
    assertThat(result).hasSize(2);
    assertThat(result).extracting(aer -> aer.getParameter()).containsExactlyInAnyOrder("1", "2");
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) Arrays(java.util.Arrays) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) AuditEventStage(com.evolveum.midpoint.audit.api.AuditEventStage) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) com.evolveum.midpoint.xml.ns._public.common.audit_3(com.evolveum.midpoint.xml.ns._public.common.audit_3) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) MiscUtil(com.evolveum.midpoint.util.MiscUtil) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) PrismObject(com.evolveum.midpoint.prism.PrismObject) NullTaskImpl(com.evolveum.midpoint.task.api.test.NullTaskImpl) CHANNEL_REST_URI(com.evolveum.midpoint.schema.constants.SchemaConstants.CHANNEL_REST_URI) Collectors(java.util.stream.Collectors) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) List(java.util.List) AuditEventType(com.evolveum.midpoint.audit.api.AuditEventType) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) ContextConfiguration(org.springframework.test.context.ContextConfiguration) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) Comparator(java.util.Comparator) NotNull(org.jetbrains.annotations.NotNull) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) Test(org.testng.annotations.Test)

Example 40 with SearchResultList

use of com.evolveum.midpoint.schema.SearchResultList in project midpoint by Evolveum.

the class SqaleRepoSearchTest method searchCaseWorkItemByOutcome.

private void searchCaseWorkItemByOutcome(String wiOutcome, String... expectedCaseOids) throws Exception {
    when("searching case with query for workitem/output/outcome " + wiOutcome);
    OperationResult operationResult = createOperationResult();
    SearchResultList<CaseType> result = searchObjects(CaseType.class, prismContext.queryFor(CaseType.class).item(CaseType.F_WORK_ITEM, CaseWorkItemType.F_OUTPUT, AbstractWorkItemOutputType.F_OUTCOME).eq(wiOutcome).build(), operationResult);
    then("case with the matching workitem outcome is returned");
    assertThatOperationResult(operationResult).isSuccess();
    assertThat(result).extracting(o -> o.getOid()).containsExactlyInAnyOrder(expectedCaseOids);
}
Also used : QFocus(com.evolveum.midpoint.repo.sqale.qmodel.focus.QFocus) XmlTypeConverter.createXMLGregorianCalendar(com.evolveum.midpoint.prism.xml.XmlTypeConverter.createXMLGregorianCalendar) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) T_PARENT(com.evolveum.midpoint.prism.PrismConstants.T_PARENT) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest) F_VALID_FROM(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType.F_VALID_FROM) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) BigDecimal(java.math.BigDecimal) DOMUtil(com.evolveum.midpoint.util.DOMUtil) Assert(org.testng.Assert) F_ACTIVATION(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType.F_ACTIVATION) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) TestUtil(com.evolveum.midpoint.test.util.TestUtil) Assertions(org.assertj.core.api.Assertions) BigInteger(java.math.BigInteger) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) MObjectType(com.evolveum.midpoint.repo.sqale.qmodel.object.MObjectType) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) QAssignmentHolder(com.evolveum.midpoint.repo.sqale.qmodel.object.QAssignmentHolder) QObject(com.evolveum.midpoint.repo.sqale.qmodel.object.QObject) BeforeClass(org.testng.annotations.BeforeClass) ORG_DEFAULT(com.evolveum.midpoint.schema.constants.SchemaConstants.ORG_DEFAULT) MiscUtil(com.evolveum.midpoint.util.MiscUtil) UUID(java.util.UUID) F_VALID_TO(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType.F_VALID_TO) Instant(java.time.Instant) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) MiscUtil.asXMLGregorianCalendar(com.evolveum.midpoint.util.MiscUtil.asXMLGregorianCalendar) PolyStringItemFilterProcessor(com.evolveum.midpoint.repo.sqlbase.filtering.item.PolyStringItemFilterProcessor) List(java.util.List) ItemName(com.evolveum.midpoint.prism.path.ItemName) SchemaService(com.evolveum.midpoint.schema.SchemaService) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) F_ASSIGNMENT(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentHolderType.F_ASSIGNMENT) SystemException(com.evolveum.midpoint.util.exception.SystemException) MObject(com.evolveum.midpoint.repo.sqale.qmodel.object.MObject) T_OBJECT_REFERENCE(com.evolveum.midpoint.prism.PrismConstants.T_OBJECT_REFERENCE) QName(javax.xml.namespace.QName) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Aggregations

SearchResultList (com.evolveum.midpoint.schema.SearchResultList)45 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)38 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)33 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)31 Test (org.testng.annotations.Test)28 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)27 List (java.util.List)27 PrismObject (com.evolveum.midpoint.prism.PrismObject)26 ObjectTypeUtil (com.evolveum.midpoint.schema.util.ObjectTypeUtil)25 OperationResultStatus (com.evolveum.midpoint.schema.result.OperationResultStatus)24 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)23 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)23 MiscUtil (com.evolveum.midpoint.util.MiscUtil)23 SqaleRepoBaseTest (com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)17 TestUtil (com.evolveum.midpoint.test.util.TestUtil)17 UUID (java.util.UUID)17 BeforeClass (org.testng.annotations.BeforeClass)17 com.evolveum.midpoint.prism (com.evolveum.midpoint.prism)14 RepositoryService (com.evolveum.midpoint.repo.api.RepositoryService)14 SystemException (com.evolveum.midpoint.util.exception.SystemException)10