use of com.evolveum.midpoint.prism.path.ItemPathSegment in project midpoint by Evolveum.
the class ExpressionUtil method resolvePath.
public static Object resolvePath(ItemPath path, ExpressionVariables variables, Object defaultContext, ObjectResolver objectResolver, String shortDesc, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException {
Object root = defaultContext;
ItemPath relativePath = path;
ItemPathSegment first = path.first();
String varDesc = "default context";
if (first.isVariable()) {
QName varName = ((NameItemPathSegment) first).getName();
varDesc = "variable " + PrettyPrinter.prettyPrint(varName);
relativePath = path.rest();
if (variables.containsKey(varName)) {
root = variables.get(varName);
} else {
throw new SchemaException("No variable with name " + varName + " in " + shortDesc);
}
}
if (root == null) {
return null;
}
if (relativePath.isEmpty()) {
return root;
}
if (root instanceof ObjectReferenceType) {
root = resolveReference((ObjectReferenceType) root, objectResolver, varDesc, shortDesc, task, result);
}
if (root instanceof Objectable) {
return (((Objectable) root).asPrismObject()).find(relativePath);
}
if (root instanceof PrismObject<?>) {
return ((PrismObject<?>) root).find(relativePath);
} else if (root instanceof PrismContainer<?>) {
return ((PrismContainer<?>) root).find(relativePath);
} else if (root instanceof PrismContainerValue<?>) {
return ((PrismContainerValue<?>) root).find(relativePath);
} else if (root instanceof Item<?, ?>) {
// Except for container (which is handled above)
throw new SchemaException("Cannot apply path " + relativePath + " to " + root + " in " + shortDesc);
} else if (root instanceof ObjectDeltaObject<?>) {
return ((ObjectDeltaObject<?>) root).findIdi(relativePath);
} else if (root instanceof ItemDeltaItem<?, ?>) {
return ((ItemDeltaItem<?, ?>) root).findIdi(relativePath);
} else {
throw new IllegalArgumentException("Unexpected root " + root + " (relative path:" + relativePath + ") in " + shortDesc);
}
}
use of com.evolveum.midpoint.prism.path.ItemPathSegment in project midpoint by Evolveum.
the class CertificationCaseHelper method checkPathSanity.
private long checkPathSanity(ItemPath deltaPath, List<Long> casesAddedOrDeleted) {
ItemPathSegment secondSegment = deltaPath.getSegments().get(1);
if (!(secondSegment instanceof IdItemPathSegment)) {
throw new IllegalStateException("Couldn't update cert campaign by delta with path " + deltaPath + " - should start with case[id]");
}
Long id = ((IdItemPathSegment) secondSegment).getId();
if (id == null) {
throw new IllegalStateException("Couldn't update cert campaign by delta with path " + deltaPath + " - should start with case[id]");
}
if (deltaPath.size() == 2) {
// not enough
throw new IllegalStateException("Couldn't update cert campaign by delta with path " + deltaPath + " - should start with case[id] and contain additional path");
}
if (casesAddedOrDeleted == null || casesAddedOrDeleted.contains(id)) {
throw new IllegalArgumentException("Couldn't update certification case that was added/deleted in this operation. Path=" + deltaPath);
}
return id;
}
use of com.evolveum.midpoint.prism.path.ItemPathSegment in project midpoint by Evolveum.
the class JpaEntityDefinition method nextLinkDefinition.
@Override
public DataSearchResult<?> nextLinkDefinition(ItemPath path, ItemDefinition<?> itemDefinition, PrismContext prismContext) throws QueryException {
if (ItemPath.isNullOrEmpty(path)) {
// doesn't fulfill precondition
return null;
}
ItemPathSegment first = path.first();
if (first instanceof IdItemPathSegment) {
throw new QueryException("ID item path segments are not allowed in query: " + path);
} else if (first instanceof ObjectReferencePathSegment) {
throw new QueryException("'@' path segment cannot be used in the context of an entity " + this);
}
JpaLinkDefinition<?> link = findRawLinkDefinition(path, JpaDataNodeDefinition.class, false);
if (link == null) {
return null;
} else {
link.resolveEntityPointer();
return new DataSearchResult<>(link, path.tail(link.getItemPath().size()));
}
}
use of com.evolveum.midpoint.prism.path.ItemPathSegment in project midpoint by Evolveum.
the class WebComponentUtil method joinPath.
public static ItemPath joinPath(ItemPath path, ItemPath deltaPath) {
List<ItemPathSegment> newPath = new ArrayList<ItemPathSegment>();
ItemPathSegment firstDeltaSegment = deltaPath != null ? deltaPath.first() : null;
if (path != null) {
for (ItemPathSegment seg : path.getSegments()) {
if (seg.equivalent(firstDeltaSegment)) {
break;
}
newPath.add(seg);
}
}
if (deltaPath != null) {
newPath.addAll(deltaPath.getSegments());
}
return new ItemPath(newPath);
}
use of com.evolveum.midpoint.prism.path.ItemPathSegment in project midpoint by Evolveum.
the class ObjectWrapperFactory method createPropertyPath.
private ItemPath createPropertyPath(ItemPath path, QName element) {
List<ItemPathSegment> segments = new ArrayList<>();
segments.addAll(path.getSegments());
segments.add(new NameItemPathSegment(element));
return new ItemPath(segments);
}
Aggregations