use of com.evolveum.midpoint.prism.match.MatchingRuleRegistry in project midpoint by Evolveum.
the class ImportProducerWorker method processStream.
private void processStream(InputStream input) throws IOException {
ApplicationContext appContext = context.getApplicationContext();
PrismContext prismContext = appContext.getBean(PrismContext.class);
MatchingRuleRegistry matchingRuleRegistry = appContext.getBean(MatchingRuleRegistry.class);
EventHandler<T> handler = new EventHandler<>() {
@Override
public EventResult preMarshall(Element objectElement, Node postValidationTree, OperationResult objectResult) {
currentOid = objectElement.getAttribute("oid");
return EventResult.cont();
}
@Override
public EventResult postMarshall(T object, Element objectElement, OperationResult objectResult) {
try {
if (filter != null) {
boolean match = ObjectQuery.match(object, filter, matchingRuleRegistry);
if (!match) {
operation.incrementSkipped();
return EventResult.skipObject("Object doesn't match filter");
}
}
if (!matchSelectedType(object.getClass())) {
operation.incrementSkipped();
return EventResult.skipObject("Type doesn't match");
}
queue.put(object);
} catch (Exception ex) {
throw new NinjaException(getErrorMessage() + ", reason: " + ex.getMessage(), ex);
}
currentOid = null;
return stopAfterFound ? EventResult.skipObject() : EventResult.cont();
}
@Override
public void handleGlobalError(OperationResult currentResult, Exception cause) {
// This should not
// Should we log error?
operation.incrementError();
String message = getErrorMessage();
if (continueOnInputError) {
if (context.isVerbose()) {
context.getLog().error(message, cause);
} else {
context.getLog().error(message + ", reason: {}", cause.getMessage());
}
} else {
// We need to throw runtime exception in order to stop validator, otherwise validator will continue
// fill queue and this may result in deadlock
operation.finish();
throw new NinjaException(message + ", reason: " + cause.getMessage(), cause);
}
}
};
// FIXME: MID-5151: If validateSchema is false we are not validating unknown attributes on import
LegacyValidator<?> validator = new LegacyValidator<>(prismContext, handler);
validator.setValidateSchema(false);
OperationResult result = operation.getResult();
Charset charset = context.getCharset();
Reader reader = new InputStreamReader(input, charset);
validator.validate(new ReaderInputStream(reader, charset), result, result.getOperation());
}
use of com.evolveum.midpoint.prism.match.MatchingRuleRegistry in project midpoint by Evolveum.
the class ProvisioningUtil method narrowPropertyDelta.
public static <T> PropertyDelta<T> narrowPropertyDelta(PropertyDelta<T> propertyDelta, PrismObject<ShadowType> currentShadow, QName overridingMatchingRuleQName, MatchingRuleRegistry matchingRuleRegistry) throws SchemaException {
ItemDefinition propertyDef = propertyDelta.getDefinition();
QName matchingRuleQName;
if (overridingMatchingRuleQName != null) {
matchingRuleQName = overridingMatchingRuleQName;
} else if (propertyDef instanceof ResourceAttributeDefinition) {
matchingRuleQName = ((ResourceAttributeDefinition<?>) propertyDef).getMatchingRuleQName();
} else {
matchingRuleQName = null;
}
MatchingRule<T> matchingRule;
if (matchingRuleQName != null && propertyDef != null) {
matchingRule = matchingRuleRegistry.getMatchingRule(matchingRuleQName, propertyDef.getTypeName());
} else {
matchingRule = null;
}
LOGGER.trace("Narrowing attr def={}, matchingRule={} ({})", propertyDef, matchingRule, matchingRuleQName);
Comparator<PrismPropertyValue<T>> comparator = (o1, o2) -> {
if (o1.equals(o2, EquivalenceStrategy.REAL_VALUE, matchingRule)) {
return 0;
} else {
return 1;
}
};
// We can safely narrow delta using real values, because we are not interested in value metadata here.
// Because we are dealing with properties, container IDs are also out of questions, and operational items
// as well.
// MID-5280
PropertyDelta<T> filteredDelta = propertyDelta.narrow(currentShadow, comparator, comparator, true);
if (filteredDelta == null || !filteredDelta.equals(propertyDelta)) {
LOGGER.trace("Narrowed delta: {}", DebugUtil.debugDumpLazily(filteredDelta));
}
return filteredDelta;
}
Aggregations