use of com.evolveum.midpoint.model.api.validator.Issue in project midpoint by Evolveum.
the class DataModelUtil method resolvePath.
// null means not supported yet
@Nullable
@SuppressWarnings("unchecked")
public static PathResolutionResult resolvePath(@NotNull ItemPath path, @NotNull PathResolutionContext context) {
if (!(path.first() instanceof NameItemPathSegment)) {
return new PathResolutionResult(new Issue(Issue.Severity.WARNING, CAT_ITEM_PATH, C_DOES_NOT_START_WITH_NAME, "Path does not start with a name: '" + path + "'", null, null));
}
QName varName;
ItemPath itemPath;
NameItemPathSegment firstNameSegment = (NameItemPathSegment) path.first();
if (firstNameSegment.isVariable()) {
varName = firstNameSegment.getName();
itemPath = path.tail();
} else {
if (context.defaultVariable == null) {
return new PathResolutionResult(new Issue(Issue.Severity.WARNING, CAT_ITEM_PATH, C_NO_DEFAULT_VARIABLE, "No default variable for item path: '" + path + "'", null, null));
}
varName = context.defaultVariable;
itemPath = path;
}
if (QNameUtil.match(ExpressionConstants.VAR_ACCOUNT, varName)) {
if (!(context instanceof ResourceResolutionContext)) {
return new PathResolutionResult(new Issue(Issue.Severity.WARNING, CAT_ITEM_PATH, C_ILLEGAL_USE_OF_ACCOUNT_VARIABLE, "Illegal use of 'account' variable: '" + path + "'", null, null));
} else {
// TODO implement checking of $account-based paths
return null;
}
} else if (QNameUtil.match(ExpressionConstants.VAR_USER, varName) || QNameUtil.match(ExpressionConstants.VAR_FOCUS, varName)) {
Class<? extends FocusType> clazz = FocusType.class;
if (context instanceof ResourceResolutionContext) {
ResourceResolutionContext rctx = (ResourceResolutionContext) context;
ObjectSynchronizationType def = ResourceTypeUtil.findObjectSynchronization(rctx.resource, rctx.kind, rctx.intent);
if (def != null) {
QName focusType = def.getFocusType() != null ? def.getFocusType() : UserType.COMPLEX_TYPE;
PrismObjectDefinition<Objectable> objdef = rctx.prismContext.getSchemaRegistry().findObjectDefinitionByType(focusType);
if (objdef != null && objdef.getCompileTimeClass() != null && FocusType.class.isAssignableFrom(objdef.getCompileTimeClass())) {
clazz = (Class) objdef.getCompileTimeClass();
}
} else {
// the default (MID-3307)
clazz = UserType.class;
}
}
return resolvePathForType(clazz, itemPath, context);
} else if (QNameUtil.match(ExpressionConstants.VAR_ACTOR, varName)) {
return resolvePathForType(UserType.class, itemPath, context);
} else if (QNameUtil.match(ExpressionConstants.VAR_INPUT, varName)) {
return null;
} else {
// TODO list all possible variables here and issue a warning if no one matches
return null;
}
}
use of com.evolveum.midpoint.model.api.validator.Issue in project midpoint by Evolveum.
the class DataModelUtil method resolvePathForType.
// null means not supported yet
@Nullable
public static PathResolutionResult resolvePathForType(@NotNull Class<? extends ObjectType> clazz, @NotNull ItemPath path, @NotNull PathResolutionContext context) {
PrismObjectDefinition<?> def = context.prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(clazz);
if (def == null) {
return new PathResolutionResult(new Issue(Issue.Severity.WARNING, CAT_ITEM_PATH, C_NO_OBJECT_DEFINITION, "No definition for " + clazz + " in item path: '" + path + "'", null, null));
}
ItemDefinition<?> itemDef = def.findItemDefinition(path);
if (itemDef != null) {
return new PathResolutionResult(itemDef);
} else {
if (FocusType.class.equals(clazz) && context instanceof ResourceResolutionContext) {
ResourceResolutionContext rctx = (ResourceResolutionContext) context;
return new PathResolutionResult(new Issue(Issue.Severity.INFO, CAT_ITEM_PATH, C_NO_OBJECT_DEFINITION, "Couldn't verify item path '" + path + "' because specific focus type (user, role, org, ...) is not defined for kind=" + rctx.kind + ", intent=" + rctx.intent, null, null));
} else {
return new PathResolutionResult(new Issue(Issue.Severity.WARNING, CAT_ITEM_PATH, C_NO_OBJECT_DEFINITION, "No definition for '" + path + "' in " + def.getName().getLocalPart(), null, null));
}
}
}
Aggregations