use of com.evolveum.midpoint.prism.path.ItemPathSegment in project midpoint by Evolveum.
the class ModificationDto method getItemName.
private static String getItemName(ItemDelta delta) {
if (delta.getDefinition() != null) {
if (delta.getDefinition().getDisplayName() != null) {
return delta.getDefinition().getDisplayName();
}
if (delta.getDefinition().getName() != null) {
return delta.getDefinition().getName().getLocalPart();
}
}
ItemPath path = delta.getPath();
for (int i = path.getSegments().size() - 1; i >= 0; i--) {
if (path.getSegments().get(i) instanceof NameItemPathSegment) {
String retval = ((NameItemPathSegment) path.getSegments().get(i)).getName().getLocalPart();
i++;
while (i < path.getSegments().size()) {
ItemPathSegment itemPathSegment = path.getSegments().get(i);
if (itemPathSegment instanceof IdItemPathSegment) {
// should always be the case
retval += "[" + ((IdItemPathSegment) itemPathSegment).getId() + "]";
}
}
return retval;
}
}
// this means there's some problem there
return delta.toString();
}
use of com.evolveum.midpoint.prism.path.ItemPathSegment in project midpoint by Evolveum.
the class ComplexTypeDefinitionImpl method findItemDefinition.
@Override
public <ID extends ItemDefinition> ID findItemDefinition(@NotNull ItemPath path, @NotNull Class<ID> clazz) {
for (; ; ) {
if (path.isEmpty()) {
throw new IllegalArgumentException("Cannot resolve empty path on complex type definition " + this);
}
ItemPathSegment first = path.first();
if (first instanceof NameItemPathSegment) {
QName firstName = ((NameItemPathSegment) first).getName();
return findNamedItemDefinition(firstName, path.rest(), clazz);
} else if (first instanceof IdItemPathSegment) {
path = path.rest();
} else if (first instanceof ParentPathSegment) {
ItemPath rest = path.rest();
ComplexTypeDefinition parent = getSchemaRegistry().determineParentDefinition(this, rest);
if (rest.isEmpty()) {
// requires that the parent is defined as an item (container, object)
return (ID) getSchemaRegistry().findItemDefinitionByType(parent.getTypeName());
} else {
return parent.findItemDefinition(rest, clazz);
}
} else if (first instanceof ObjectReferencePathSegment) {
throw new IllegalStateException("Couldn't use '@' path segment in this context. CTD=" + getTypeName() + ", path=" + path);
} else {
throw new IllegalStateException("Unexpected path segment: " + first + " in " + path);
}
}
}
use of com.evolveum.midpoint.prism.path.ItemPathSegment in project midpoint by Evolveum.
the class PrismContainerDefinitionImpl method findItemDefinition.
public <ID extends ItemDefinition> ID findItemDefinition(@NotNull ItemPath path, @NotNull Class<ID> clazz) {
for (; ; ) {
if (path.isEmpty()) {
if (clazz.isAssignableFrom(PrismContainerDefinition.class)) {
return (ID) this;
} else {
return null;
}
}
ItemPathSegment first = path.first();
if (first instanceof NameItemPathSegment) {
QName firstName = ((NameItemPathSegment) first).getName();
return findNamedItemDefinition(firstName, path.rest(), clazz);
} else if (first instanceof IdItemPathSegment) {
path = path.rest();
} else if (first instanceof ParentPathSegment) {
ItemPath rest = path.rest();
ComplexTypeDefinition parent = getSchemaRegistry().determineParentDefinition(getComplexTypeDefinition(), rest);
if (rest.isEmpty()) {
// requires that the parent is defined as an item (container, object)
return (ID) getSchemaRegistry().findItemDefinitionByType(parent.getTypeName());
} else {
return parent.findItemDefinition(rest, clazz);
}
} else if (first instanceof ObjectReferencePathSegment) {
throw new IllegalStateException("Couldn't use '@' path segment in this context. PCD=" + getTypeName() + ", path=" + path);
} else {
throw new IllegalStateException("Unexpected path segment: " + first + " in " + path);
}
}
}
use of com.evolveum.midpoint.prism.path.ItemPathSegment in project midpoint by Evolveum.
the class ShadowUtil method getAttributeName.
public static QName getAttributeName(ItemPath attributePath, String message) throws SchemaException {
if (attributePath == null || attributePath.isEmpty()) {
return null;
}
ItemPathSegment firstPathSegment = attributePath.first();
if (!(firstPathSegment instanceof NameItemPathSegment)) {
throw new SchemaException(message + ": first path segment is not a name segment");
}
if (!QNameUtil.match(ShadowType.F_ATTRIBUTES, ((NameItemPathSegment) firstPathSegment).getName())) {
throw new SchemaException(message + ": first path segment is not " + ShadowType.F_ATTRIBUTES);
}
if (attributePath.size() < 1) {
throw new SchemaException(message + ": path too short (" + attributePath.size() + " segments)");
}
if (attributePath.size() > 2) {
throw new SchemaException(message + ": path too long (" + attributePath.size() + " segments)");
}
ItemPathSegment secondPathSegment = attributePath.getSegments().get(1);
if (!(secondPathSegment instanceof NameItemPathSegment)) {
throw new SchemaException(message + ": second path segment is not a name segment");
}
return ((NameItemPathSegment) secondPathSegment).getName();
}
use of com.evolveum.midpoint.prism.path.ItemPathSegment in project midpoint by Evolveum.
the class TextFormatter method getItemPathLabel.
private String getItemPathLabel(ItemPath path, Definition deltaDefinition, PrismObjectDefinition objectDefinition) {
NameItemPathSegment lastNamedSegment = path.lastNamed();
StringBuilder sb = new StringBuilder();
for (ItemPathSegment segment : path.getSegments()) {
if (segment instanceof NameItemPathSegment) {
if (sb.length() > 0) {
sb.append("/");
}
Definition itemDefinition;
if (objectDefinition == null) {
if (segment == lastNamedSegment) {
// definition for last segment is the definition taken from delta
// this may be null but we don't care
itemDefinition = deltaDefinition;
} else {
// definitions for previous segments are unknown
itemDefinition = null;
}
} else {
// todo we could make this iterative (resolving definitions while walking down the path); but this is definitely simpler to implement and debug :)
itemDefinition = objectDefinition.findItemDefinition(path.allUpToIncluding(segment));
}
if (itemDefinition != null && itemDefinition.getDisplayName() != null) {
sb.append(resolve(itemDefinition.getDisplayName()));
} else {
sb.append(((NameItemPathSegment) segment).getName().getLocalPart());
}
} else if (segment instanceof IdItemPathSegment) {
sb.append("[").append(((IdItemPathSegment) segment).getId()).append("]");
}
}
return sb.toString();
}
Aggregations