use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.
the class AbstractSearchExpressionEvaluator method evaluatePopulateExpression.
private <IV extends PrismValue, ID extends ItemDefinition, C extends Containerable> ItemDelta<IV, ID> evaluatePopulateExpression(PopulateItemType populateItem, ExpressionVariables variables, ExpressionEvaluationContext params, PrismContainerDefinition<C> objectDefinition, String contextDescription, boolean evaluateMinus, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
ExpressionType expressionType = populateItem.getExpression();
if (expressionType == null) {
LOGGER.warn("No expression in populateObject in assignment expression in {}, " + "skipping. Subsequent operations will most likely fail", contextDescription);
return null;
}
VariableBindingDefinitionType targetType = populateItem.getTarget();
if (targetType == null) {
LOGGER.warn("No target in populateObject in assignment expression in {}, " + "skipping. Subsequent operations will most likely fail", contextDescription);
return null;
}
ItemPathType itemPathType = targetType.getPath();
if (itemPathType == null) {
throw new SchemaException("No path in target definition in " + contextDescription);
}
ItemPath targetPath = itemPathType.getItemPath();
ID propOutputDefinition = ExpressionUtil.resolveDefinitionPath(targetPath, variables, objectDefinition, "target definition in " + contextDescription);
if (propOutputDefinition == null) {
throw new SchemaException("No target item that would conform to the path " + targetPath + " in " + contextDescription);
}
String expressionDesc = "expression in assignment expression in " + contextDescription;
ExpressionFactory expressionFactory = params.getExpressionFactory();
Expression<IV, ID> expression = expressionFactory.makeExpression(expressionType, propOutputDefinition, expressionDesc, task, result);
ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, variables, expressionDesc, task, result);
context.setExpressionFactory(expressionFactory);
context.setStringPolicyResolver(params.getStringPolicyResolver());
context.setDefaultTargetContext(params.getDefaultTargetContext());
context.setSkipEvaluationMinus(true);
context.setSkipEvaluationPlus(false);
PrismValueDeltaSetTriple<IV> outputTriple = expression.evaluate(context);
LOGGER.trace("output triple: {}", outputTriple.debugDump());
Collection<IV> pvalues = outputTriple.getNonNegativeValues();
// Maybe not really clean but it works. TODO: refactor later
NameItemPathSegment first = (NameItemPathSegment) targetPath.first();
if (first.isVariable()) {
targetPath = targetPath.rest();
}
ItemDelta<IV, ID> itemDelta = propOutputDefinition.createEmptyDelta(targetPath);
itemDelta.addValuesToAdd(PrismValue.cloneCollection(pvalues));
LOGGER.trace("Item delta:\n{}", itemDelta.debugDump());
return itemDelta;
}
use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.
the class ObjectValuePolicyEvaluator method preparePassword.
private void preparePassword() {
if (!QNameUtil.match(UserType.F_CREDENTIALS, valueItemPath.getFirstName())) {
return;
}
ItemPathSegment secondPathSegment = valueItemPath.getSegments().get(1);
if (!(secondPathSegment instanceof NameItemPathSegment)) {
return;
}
credentialQName = ((NameItemPathSegment) secondPathSegment).getName();
if (!QNameUtil.match(CredentialsType.F_PASSWORD, credentialQName)) {
return;
}
credentialPolicy = SecurityUtil.getEffectivePasswordCredentialsPolicy(securityPolicy);
}
use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.
the class DataModelVisualizerImpl method resolveSourceItem.
// for outbound (but sometimes also inbound) mappings
@NotNull
private DataItem resolveSourceItem(@NotNull DataModel model, @NotNull ResourceDataItem currentItem, @NotNull MappingType mapping, @NotNull ItemPath path, @Nullable QName defaultVariable) {
if (!(path.first() instanceof NameItemPathSegment)) {
LOGGER.warn("Probably incorrect path ({}) - does not start with a name - skipping", path);
return createAdHocDataItem(model, path);
}
QName varName;
ItemPath itemPath;
NameItemPathSegment firstNameSegment = (NameItemPathSegment) path.first();
if (firstNameSegment.isVariable()) {
varName = firstNameSegment.getName();
itemPath = path.tail();
} else {
if (defaultVariable == null) {
LOGGER.warn("No default variable for mapping source");
return createAdHocDataItem(model, path);
}
varName = defaultVariable;
itemPath = path;
}
if (QNameUtil.match(ExpressionConstants.VAR_ACCOUNT, varName)) {
return resolveResourceItem(model, currentItem, itemPath);
} else if (QNameUtil.match(ExpressionConstants.VAR_USER, varName)) {
return model.resolveRepositoryItem(UserType.class, itemPath);
} else if (QNameUtil.match(ExpressionConstants.VAR_ACTOR, varName)) {
// TODO
return model.resolveRepositoryItem(UserType.class, itemPath);
} else if (QNameUtil.match(ExpressionConstants.VAR_FOCUS, varName)) {
Class<? extends ObjectType> guessedClass = guessFocusClass(currentItem.getResourceOid(), currentItem.getKind(), currentItem.getIntent());
DataItem item = model.resolveRepositoryItem(guessedClass, itemPath);
if (item != null) {
return item;
}
// TODO guess e.g. by item existence in schema
LOGGER.warn("Couldn't resolve {} in $focus", path);
} else if (QNameUtil.match(ExpressionConstants.VAR_INPUT, varName)) {
return currentItem;
} else {
LOGGER.warn("Unsupported variable {} in {}", varName, path);
}
return createAdHocDataItem(model, path);
}
use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.
the class DataModelVisualizerImpl method resolveTargetItem.
// currently for inbounds only
@NotNull
private DataItem resolveTargetItem(@NotNull DataModel model, @NotNull ResourceDataItem currentItem, @NotNull MappingType mapping, @NotNull ItemPath path, @Nullable QName defaultVariable) {
if (!(path.first() instanceof NameItemPathSegment)) {
LOGGER.warn("Probably incorrect path ({}) - does not start with a name - skipping", path);
return createAdHocDataItem(model, path);
}
QName varName;
ItemPath itemPath;
NameItemPathSegment firstNameSegment = (NameItemPathSegment) path.first();
if (firstNameSegment.isVariable()) {
varName = firstNameSegment.getName();
itemPath = path.tail();
} else {
if (defaultVariable == null) {
LOGGER.warn("No default variable for mapping target");
return createAdHocDataItem(model, path);
}
varName = defaultVariable;
itemPath = path;
}
if (QNameUtil.match(ExpressionConstants.VAR_ACCOUNT, varName)) {
// does make sense?
return resolveResourceItem(model, currentItem, itemPath);
} else if (QNameUtil.match(ExpressionConstants.VAR_USER, varName)) {
return model.resolveRepositoryItem(UserType.class, itemPath);
} else if (QNameUtil.match(ExpressionConstants.VAR_ACTOR, varName)) {
// TODO
return model.resolveRepositoryItem(UserType.class, itemPath);
} else if (QNameUtil.match(ExpressionConstants.VAR_FOCUS, varName)) {
Class<? extends ObjectType> guessedClass = guessFocusClass(currentItem.getResourceOid(), currentItem.getKind(), currentItem.getIntent());
DataItem item = model.resolveRepositoryItem(guessedClass, itemPath);
if (item != null) {
return item;
}
// TODO guess e.g. by item existence in schema
LOGGER.warn("Couldn't resolve {} in $focus", path);
} else if (QNameUtil.match(ExpressionConstants.VAR_INPUT, varName)) {
// does make sense?
return currentItem;
} else {
LOGGER.warn("Unsupported variable {} in {}", varName, path);
}
return createAdHocDataItem(model, path);
}
use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.
the class ModelController method resolve.
// TODO clean this mess
private <O extends ObjectType> void resolve(Containerable containerable, ItemPath path, SelectorOptions<GetOperationOptions> option, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, SecurityViolationException, ConfigurationException {
if (path == null || path.isEmpty()) {
return;
}
ItemPathSegment first = path.first();
ItemPath rest = path.rest();
PrismContainerValue<?> containerValue = containerable.asPrismContainerValue();
if (first instanceof NameItemPathSegment) {
QName refName = ItemPath.getName(first);
PrismReference reference = containerValue.findReferenceByCompositeObjectElementName(refName);
if (reference == null) {
// alternatively look up by reference name (e.g. linkRef)
reference = containerValue.findReference(refName);
}
if (reference != null) {
for (PrismReferenceValue refVal : reference.getValues()) {
PrismObject<O> refObject = refVal.getObject();
if (refObject == null) {
refObject = objectResolver.resolve(refVal, containerable.toString(), option.getOptions(), task, result);
refObject = refObject.cloneIfImmutable();
schemaTransformer.applySchemasAndSecurity(refObject, option.getOptions(), null, task, result);
refVal.setObject(refObject);
}
if (!rest.isEmpty()) {
resolve(refObject.asObjectable(), rest, option, task, result);
}
}
return;
}
}
if (rest.isEmpty()) {
return;
}
if (first instanceof ParentPathSegment) {
PrismContainerValue<?> parent = containerValue.getParentContainerValue();
if (parent != null) {
resolve(parent.asContainerable(), rest, option, task, result);
}
} else {
QName nextName = ItemPath.getName(first);
PrismContainer<?> nextContainer = containerValue.findContainer(nextName);
if (nextContainer != null) {
for (PrismContainerValue<?> pcv : nextContainer.getValues()) {
resolve(pcv.asContainerable(), rest, option, task, result);
}
}
}
}
Aggregations