Search in sources :

Example 21 with SearchResultList

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

the class AuditSearchTest method test253SearchByChangedItemsPrefixOfComplexPath.

@Test
public void test253SearchByChangedItemsPrefixOfComplexPath() throws SchemaException {
    when("searching audit by changed items equal to the prefix of complex path");
    SearchResultList<AuditEventRecordType> result = searchObjects(prismContext.queryFor(AuditEventRecordType.class).item(AuditEventRecordType.F_CHANGED_ITEM).eq(new ItemPathType(ObjectType.F_METADATA)).build());
    then("only audit events with the specified changed items are returned");
    // this is more about the audit writing than reading, but it is here to cover all the expectations
    assertThat(result).hasSize(1);
    assertThat(result).extracting(aer -> aer.getParameter()).containsExactlyInAnyOrder("1");
}
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 22 with SearchResultList

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

the class AuditSearchTest method test250SearchByChangedItemsSimplePath.

@Test
public void test250SearchByChangedItemsSimplePath() throws SchemaException {
    when("searching audit by changed items equal to simple path");
    SearchResultList<AuditEventRecordType> result = searchObjects(prismContext.queryFor(AuditEventRecordType.class).item(AuditEventRecordType.F_CHANGED_ITEM).eq(new ItemPathType(UserType.F_FULL_NAME)).build());
    then("audit events with the 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 23 with SearchResultList

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

the class NodeIdComputer method getNodeIdFromExpression.

private String getNodeIdFromExpression(ConfigurationInterpolator parentInterpolator, String expression, OperationResult result) {
    SequenceLookup sequenceLookup = new SequenceLookup();
    InterpolatorSpecification sequenceProvidingInterpolatorSpec = new InterpolatorSpecification.Builder().withParentInterpolator(parentInterpolator).withPrefixLookup("sequence", sequenceLookup).create();
    ConfigurationInterpolator interpolator = ConfigurationInterpolator.fromSpecification(sequenceProvidingInterpolatorSpec);
    for (int attempt = 0; ; attempt++) {
        Object interpolationResult = interpolator.interpolate(expression);
        if (!(interpolationResult instanceof String)) {
            LOGGER.warn("Node ID expression '{}' returned null or non-String value: {}", expression, interpolationResult);
            return null;
        }
        String candidateNodeId = (String) interpolationResult;
        if (candidateNodeId.contains("${")) {
            // This is a bit of hack: it looks like the node was not resolved correctly.
            throw new SystemException("Looks like we couldn't resolve the node ID expression. The (partial) result is: '" + candidateNodeId + "'");
        }
        if (sequenceLookup.iterationRequired) {
            try {
                // Let us try to create node with given name. If we fail we know we need to iterate.
                // If we succeed, we will (later) replace the node with the correct content.
                // Note that we set (fake) last check-in time here so this node will not be accidentally cleaned-up.
                // TODO consider moving this addObject call to NodeRegistrar (requires cleanup of the mix of
                // Spring injected and manually created objects)
                NodeType node = new NodeType(prismContext).name(candidateNodeId).lastCheckInTime(XmlTypeConverter.createXMLGregorianCalendar());
                repositoryService.addObject(node.asPrismObject(), null, result);
            } catch (ObjectAlreadyExistsException e) {
                // We have a conflict. But the node might be - in fact - dead. So let's try to reclaim it if possible.
                String nodeIdNorm = prismContext.getDefaultPolyStringNormalizer().normalize(candidateNodeId);
                SearchResultList<PrismObject<NodeType>> existingNodes;
                try {
                    existingNodes = repositoryService.searchObjects(NodeType.class, prismContext.queryFor(NodeType.class).item(NodeType.F_NAME).eqPoly(candidateNodeId, nodeIdNorm).matchingNorm().build(), null, result);
                } catch (SchemaException ex) {
                    throw new SystemException("Unexpected schema exception while looking for node '" + candidateNodeId + "': " + e.getMessage(), e);
                }
                if (existingNodes.isEmpty()) {
                    // Strange. The node should have gone in the meanwhile. To be safe, let's try another one.
                    LOGGER.warn("Node name '{}' seemed to be already reserved. But it cannot be found now. Iterating to the" + " next one (if possible).", candidateNodeId);
                    sequenceLookup.advance();
                } else if (existingNodes.size() > 1) {
                    LOGGER.warn("Strange: More than one node with the name of '{}': {}. Trying next name in the sequence" + "(if possible).", candidateNodeId, existingNodes);
                    sequenceLookup.advance();
                } else {
                    NodeType existingNode = existingNodes.get(0).asObjectable();
                    if (existingNode.getOperationalState() == NodeOperationalStateType.DOWN) {
                        LOGGER.info("Considering using the node name of '{}' that already exists but is marked as being down" + " (OID {}). So deleting the node and trying again.", candidateNodeId, existingNode.getOid());
                        try {
                            repositoryService.deleteObject(NodeType.class, existingNode.getOid(), result);
                        } catch (ObjectNotFoundException ex) {
                            LoggingUtils.logExceptionAsWarning(LOGGER, "Couldn't delete the node {}. Probably someone" + " else is faster than us.", ex, existingNode);
                        }
                    // no advance here
                    } else {
                        LOGGER.debug("Node name '{}' is already reserved. Iterating to next one (if possible).", candidateNodeId);
                        sequenceLookup.advance();
                    }
                }
                if (attempt > MAX_ATTEMPTS_SAFEGUARD) {
                    throw new SystemException("Maximum attempts safeguard value of " + MAX_ATTEMPTS_SAFEGUARD + " has been reached. " + "Something very strange must have happened.");
                } else if (sequenceLookup.isOutOfNumbers()) {
                    throw new SystemException("Cannot acquire node name. The sequence upper border (" + sequenceLookup.end + ") has been reached.");
                } else {
                    continue;
                }
            } catch (SchemaException e) {
                throw new SystemException("Unexpected schema exception while creating temporary node: " + e.getMessage(), e);
            }
        }
        return candidateNodeId;
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) SystemException(com.evolveum.midpoint.util.exception.SystemException) InterpolatorSpecification(org.apache.commons.configuration2.interpol.InterpolatorSpecification) NodeType(com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismObject(com.evolveum.midpoint.prism.PrismObject) ConfigurationInterpolator(org.apache.commons.configuration2.interpol.ConfigurationInterpolator) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 24 with SearchResultList

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

the class AuditSearchTest method test253SearchByChangedItemsPrefixOfComplexPath.

@Test
public void test253SearchByChangedItemsPrefixOfComplexPath() throws SchemaException {
    when("searching audit by changed items equal to the prefix of complex path");
    SearchResultList<AuditEventRecordType> result = searchObjects(prismContext.queryFor(AuditEventRecordType.class).item(AuditEventRecordType.F_CHANGED_ITEM).eq(new ItemPathType(ObjectType.F_METADATA)).build());
    then("only audit events with the specified changed items are returned");
    // this is more about the audit writing than reading, but it is here to cover all the expectations
    assertThat(result).hasSize(1);
    assertThat(result).extracting(aer -> aer.getParameter()).containsExactlyInAnyOrder("1");
}
Also used : 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) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest) 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) BeforeClass(org.testng.annotations.BeforeClass) MiscUtil(com.evolveum.midpoint.util.MiscUtil) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) UUID(java.util.UUID) 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) 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) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)

Example 25 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 : 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) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest) 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) BeforeClass(org.testng.annotations.BeforeClass) MiscUtil(com.evolveum.midpoint.util.MiscUtil) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) UUID(java.util.UUID) 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) 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) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)

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