import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingInstanceIdentifierCodec;
import org.opendaylight.mdsal.eos.dom.api.DOMEntity;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.EntityName;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.EntityType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntitiesOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.NodeName;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.get.entities.output.EntitiesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.core.general.entity.rev150930.Entity;
import org.opendaylight.yangtools.yang.binding.util.BindingMap;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
this.owners = ImmutableMap.copyOf(owners);
}
- public @NonNull GetEntitiesOutput toOutput() {
+ public @NonNull GetEntitiesOutput toOutput(final BindingInstanceIdentifierCodec iidCodec) {
final Set<DOMEntity> entities = new HashSet<>();
entities.addAll(owners.keySet());
entities.addAll(candidates.keySet());
.map(entity -> {
final EntitiesBuilder eb = new EntitiesBuilder()
.setType(new EntityType(entity.getType()))
- .setName(extractName(entity))
+ .setName(extractName(entity, iidCodec))
.setCandidateNodes(candidates.get(entity).stream()
.map(NodeName::new).collect(Collectors.toUnmodifiableList()));
.build();
}
- private static EntityName extractName(final DOMEntity entity) {
- final PathArgument last = entity.getIdentifier().getLastPathArgument();
+ /**
+ * if the entity is general entity then shorthand the name to only the last path argument, otherwise return
+ * full YIID path encoded as string.
+ *
+ * @param entity Entity to extract the name from
+ * @param iidCodec codec to encode entity name back to InstanceIdentifier if needed
+ * @return Extracted name
+ */
+ private static EntityName extractName(final DOMEntity entity, final BindingInstanceIdentifierCodec iidCodec) {
+ final var id = entity.getIdentifier();
+ if (id.isEmpty() || !id.getPathArguments().get(0).getNodeType().equals(Entity.QNAME)) {
+ return new EntityName(iidCodec.toBinding(id));
+ }
+
+ final PathArgument last = id.getLastPathArgument();
verify(last instanceof NodeIdentifierWithPredicates, "Unexpected last argument %s", last);
final Object value = Iterables.getOnlyElement(((NodeIdentifierWithPredicates) last).values());
verify(value instanceof String, "Unexpected predicate value %s", value);