use of com.evolveum.midpoint.xml.ns._public.common.common_3.VariableBindingDefinitionType in project midpoint by Evolveum.
the class MappingParser method parseSource.
private <IV extends PrismValue, ID extends ItemDefinition<?>> Source<IV, ID> parseSource(VariableBindingDefinitionType sourceDefinition, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
ItemPath path = getSourcePath(sourceDefinition);
@NotNull QName sourceQName = sourceDefinition.getName() != null ? sourceDefinition.getName() : ItemPath.toName(path.last());
String variableName = sourceQName.getLocalPart();
TypedValue<?> typedSourceObject = ExpressionUtil.resolvePathGetTypedValue(path, m.variables, true, m.getTypedSourceContext(), m.beans.objectResolver, m.beans.prismContext, "source definition in " + m.getMappingContextDescription(), m.getTask(), result);
Object sourceObject = typedSourceObject != null ? typedSourceObject.getValue() : null;
Item<IV, ID> itemOld = null;
ItemDelta<IV, ID> delta = null;
Item<IV, ID> itemNew = null;
ItemPath resolvePath = path;
ItemPath residualPath = null;
Collection<? extends ItemDelta<?, ?>> subItemDeltas = null;
if (sourceObject != null) {
if (sourceObject instanceof ItemDeltaItem<?, ?>) {
// noinspection unchecked
itemOld = ((ItemDeltaItem<IV, ID>) sourceObject).getItemOld();
// noinspection unchecked
delta = ((ItemDeltaItem<IV, ID>) sourceObject).getDelta();
// noinspection unchecked
itemNew = ((ItemDeltaItem<IV, ID>) sourceObject).getItemNew();
// noinspection unchecked
residualPath = ((ItemDeltaItem<IV, ID>) sourceObject).getResidualPath();
// noinspection unchecked
resolvePath = ((ItemDeltaItem<IV, ID>) sourceObject).getResolvePath();
// noinspection unchecked
subItemDeltas = ((ItemDeltaItem<IV, ID>) sourceObject).getSubItemDeltas();
} else if (sourceObject instanceof Item<?, ?>) {
// noinspection unchecked
itemOld = (Item<IV, ID>) sourceObject;
// noinspection unchecked
itemNew = (Item<IV, ID>) sourceObject;
} else {
throw new IllegalStateException("Unknown resolve result " + sourceObject);
}
}
ID sourceItemDefinition = typedSourceObject != null ? typedSourceObject.getDefinition() : null;
// apply domain
ValueSetDefinitionType domainSetType = sourceDefinition.getSet();
if (domainSetType != null) {
ValueSetDefinition<IV, ID> setDef = new ValueSetDefinition<>(domainSetType, sourceItemDefinition, m.valueMetadataDefinition, m.expressionProfile, variableName, null, "domain of " + variableName, "domain of " + variableName + " in " + m.getMappingContextDescription(), m.getTask(), result);
setDef.init(m.beans.expressionFactory);
setDef.setAdditionalVariables(m.variables);
try {
if (itemOld != null) {
// noinspection unchecked
itemOld = itemOld.clone();
itemOld.filterValues(setDef::containsTunnel);
itemOld.filterYields(setDef::containsYieldTunnel);
}
if (itemNew != null) {
// noinspection unchecked
itemNew = itemNew.clone();
itemNew.filterValues(setDef::containsTunnel);
itemNew.filterYields(setDef::containsYieldTunnel);
}
if (delta != null) {
delta = delta.clone();
delta.filterValues(setDef::containsTunnel);
delta.filterYields(setDef::containsYieldTunnel);
}
} catch (TunnelException te) {
unwrapTunnelException(te);
}
}
Source<IV, ID> source = new Source<>(itemOld, delta, itemNew, sourceQName, sourceItemDefinition);
source.setResidualPath(residualPath);
source.setResolvePath(resolvePath);
source.setSubItemDeltas(subItemDeltas);
return source;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.VariableBindingDefinitionType in project midpoint by Evolveum.
the class TimeConstraintsEvaluation method parseTime.
private XMLGregorianCalendar parseTime(MappingTimeDeclarationType timeBean, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
if (timeBean == null) {
return null;
}
XMLGregorianCalendar referenceTime;
ExpressionType expressionBean = timeBean.getExpression();
VariableBindingDefinitionType referenceTimeBean = timeBean.getReferenceTime();
if (referenceTimeBean == null) {
if (expressionBean == null) {
throw new SchemaException("No reference time specified, there is also no default and no expression; in time specification in " + m.getMappingContextDescription());
} else {
referenceTime = null;
}
} else {
referenceTime = parseTimeSource(referenceTimeBean, result);
}
LOGGER.trace("reference time = {}", referenceTime);
XMLGregorianCalendar time;
if (expressionBean == null) {
if (referenceTime == null) {
return null;
} else {
time = (XMLGregorianCalendar) referenceTime.clone();
}
} else {
MutablePrismPropertyDefinition<XMLGregorianCalendar> timeDefinition = m.beans.prismContext.definitionFactory().createPropertyDefinition(ExpressionConstants.OUTPUT_ELEMENT_NAME, PrimitiveType.XSD_DATETIME);
timeDefinition.setMaxOccurs(1);
VariablesMap timeVariables = new VariablesMap();
timeVariables.addVariableDefinitions(m.variables);
timeVariables.addVariableDefinition(ExpressionConstants.VAR_REFERENCE_TIME, referenceTime, timeDefinition);
PrismPropertyValue<XMLGregorianCalendar> timePropVal = ExpressionUtil.evaluateExpression(m.sources, timeVariables, timeDefinition, expressionBean, m.expressionProfile, m.beans.expressionFactory, "time expression in " + m.getMappingContextDescription(), m.getTask(), result);
if (timePropVal == null) {
return null;
}
time = timePropVal.getValue();
LOGGER.trace("Expression evaluated. Time = {}", time);
}
Duration offset = timeBean.getOffset();
if (offset != null) {
time.add(offset);
LOGGER.trace("Offset {} applied; time = {}", offset, time);
}
return time;
}
Aggregations