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");
}
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");
}
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;
}
}
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");
}
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");
}
Aggregations