import static org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.STREAM_PATH;
import static org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.STREAM_PATH_PART;
+import com.google.common.collect.ImmutableList;
import java.net.URI;
import java.time.Clock;
import java.time.LocalDateTime;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMActionResult;
import org.opendaylight.mdsal.dom.api.DOMMountPoint;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.restconf.common.context.NormalizedNodeContext;
import org.opendaylight.restconf.common.context.WriterParameters;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final URI uri = streamUtils.prepareUriByStreamName(uriInfo, listener.getStreamName());
final NormalizedNode<?, ?> mapToStreams =
RestconfMappingNodeUtil.mapYangNotificationStreamByIetfRestconfMonitoring(
- listener.getSchemaPath().getLastComponent(), schemaContext.getNotifications(), null,
+ listener.getSchemaPath().lastNodeIdentifier(), schemaContext.getNotifications(), null,
listener.getOutputType(), uri, SubscribeToStreamUtil.getMonitoringModule(schemaContext), exist);
writeDataToDS(schemaContext,
- listener.getSchemaPath().getLastComponent().getLocalName(), strategy, exist, mapToStreams);
+ listener.getSchemaPath().lastNodeIdentifier().getLocalName(), strategy, exist, mapToStreams);
}
private static boolean checkExist(final EffectiveModelContext schemaContext, final RestconfStrategy strategy) {
final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
final EffectiveModelContext ref = mountPoint == null
- ? this.schemaContextHandler.get()
- : mountPoint.getEffectiveModelContext();
+ ? this.schemaContextHandler.get() : modelContext(mountPoint);
final RestconfStrategy strategy = getRestconfStrategy(mountPoint);
return PutDataTransactionUtil.putData(payload, ref, strategy, checkedParms.insert, checkedParms.point);
insertUsed = true;
final String str = entry.getValue().get(0);
- insert = Insert.valueOf(str);
+ insert = Insert.forValue(str);
if (insert == null) {
throw new RestconfDocumentedException("Unrecognized insert parameter value '" + str + "'",
RestconfError.ErrorType.PROTOCOL, RestconfError.ErrorTag.BAD_ELEMENT);
RestconfError.ErrorType.PROTOCOL, RestconfError.ErrorTag.BAD_ELEMENT);
}
- if (insert != Insert.BEFORE || insert != Insert.AFTER) {
+ if (insert != Insert.BEFORE && insert != Insert.AFTER) {
throw new RestconfDocumentedException(
"Point parameter can be used only with 'after' or 'before' values of Insert parameter.",
RestconfError.ErrorType.PROTOCOL, RestconfError.ErrorTag.BAD_ELEMENT);
final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
final EffectiveModelContext ref = mountPoint == null
- ? this.schemaContextHandler.get()
- : mountPoint.getEffectiveModelContext();
+ ? this.schemaContextHandler.get() : modelContext(mountPoint);
final RestconfStrategy strategy = getRestconfStrategy(mountPoint);
return PlainPatchDataTransactionUtil.patchData(payload, strategy, ref);
}
private EffectiveModelContext getSchemaContext(final DOMMountPoint mountPoint) {
- return mountPoint == null ? schemaContextHandler.get() : mountPoint.getEffectiveModelContext();
+ return mountPoint == null ? schemaContextHandler.get() : modelContext(mountPoint);
}
// FIXME: why is this synchronized?
public Response invokeAction(final NormalizedNodeContext payload) {
final InstanceIdentifierContext<?> context = payload.getInstanceIdentifierContext();
final DOMMountPoint mountPoint = context.getMountPoint();
- final SchemaPath schemaPath = context.getSchemaNode().getPath();
+ final Absolute schemaPath = Absolute.of(ImmutableList.copyOf(context.getSchemaNode().getPath()
+ .getPathFromRoot()));
final YangInstanceIdentifier yangIIdContext = context.getInstanceIdentifier();
final NormalizedNode<?, ?> data = payload.getData();
if (mountPoint != null) {
response = RestconfInvokeOperationsUtil.invokeActionViaMountPoint(mountPoint, (ContainerNode) data,
schemaPath, yangIIdContext);
- schemaContextRef = mountPoint.getEffectiveModelContext();
+ schemaContextRef = modelContext(mountPoint);
} else {
response = RestconfInvokeOperationsUtil.invokeAction((ContainerNode) data, schemaPath,
this.actionServiceHandler, yangIIdContext);
return Response.status(200).entity(new NormalizedNodeContext(new InstanceIdentifierContext<>(yangIIdContext,
resultNodeSchema, mountPoint, schemaContextRef), resultData)).build();
}
+
+ private static EffectiveModelContext modelContext(final DOMMountPoint mountPoint) {
+ return mountPoint.getService(DOMSchemaService.class)
+ .flatMap(svc -> Optional.ofNullable(svc.getGlobalContext()))
+ .orElse(null);
+ }
}