/** * If the path consists of a single name segment (not variable nor special symbol), returns the corresponding value. * Otherwise throws an exception. */ @NotNull default ItemName asSingleNameOrFail() { if (isSingleName()) { return ItemPath.toName(first()); } else { throw new IllegalArgumentException("Expected a single-name path, bug got "+this); } }
@Override public void trimTo(@NotNull Collection<ItemPath> paths) { originalObjectClassDefinition.trimTo(paths); List<QName> names = paths.stream() .filter(p -> p.isSingleName()) .map(p -> p.asSingleName()) .collect(Collectors.toList()); attributeDefinitions.removeIf(itemDefinition -> !QNameUtil.contains(names, itemDefinition.getName())); associationDefinitions.removeIf(itemDefinition -> !QNameUtil.contains(names, itemDefinition.getName())); }
/** * If the path consists of a single name segment (not variable nor special symbol), returns the corresponding value. * Otherwise returns null. */ default QName asSingleName() { return isSingleName() ? ItemPath.toName(first()) : null; }
@Override public ResourceAttributeDefinition findAttributeDefinition(ItemPath elementPath) { if (elementPath.isSingleName()) { // this is a bit of hack return findLocalItemDefinition(elementPath.asSingleNameOrFail(), ResourceAttributeDefinition.class, false); } else { return findItemDefinition(elementPath, ResourceAttributeDefinition.class); } }
@Override public DataSearchResult nextLinkDefinition(ItemPath path, ItemDefinition itemDefinition, PrismContext prismContext) throws QueryException { if (!path.isSingleName()) { throw new QueryException("Couldn't resolve paths other than those in the form of single name in extension/attributes container: " + path); } if (itemDefinition == null) { throw new QueryException("Couldn't resolve dynamically defined item path '" + path + "' without proper definition"); } CollectionSpecification collSpec = itemDefinition.isSingleValue() ? null : new CollectionSpecification(); String jpaName; // longs, strings, ... JpaDataNodeDefinition jpaNodeDefinition; if (itemDefinition instanceof PrismPropertyDefinition) { try { jpaName = RAnyConverter.getAnySetType(itemDefinition, prismContext); } catch (SchemaException e) { throw new QueryException(e.getMessage(), e); } jpaNodeDefinition = new JpaAnyPropertyDefinition(Object.class, null); // TODO } else if (itemDefinition instanceof PrismReferenceDefinition) { jpaName = "references"; jpaNodeDefinition = new JpaAnyReferenceDefinition(Object.class, RObject.class); } else { throw new QueryException("Unsupported 'any' item: " + itemDefinition); } JpaLinkDefinition<?> linkDefinition = new JpaAnyItemLinkDefinition(itemDefinition, jpaName, collSpec, getOwnerType(), jpaNodeDefinition); return new DataSearchResult<>(linkDefinition, ItemPath.EMPTY_PATH); }