*/
package org.opendaylight.restconf.common.context;
-import java.util.HashMap;
-import java.util.Map;
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.collect.ImmutableMap;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
public class NormalizedNodeContext {
-
private final InstanceIdentifierContext<? extends SchemaNode> context;
+ private final ImmutableMap<String, Object> headers;
private final WriterParameters writerParameters;
private final NormalizedNode data;
- private Map<String, Object> headers = new HashMap<>();
-
public NormalizedNodeContext(final InstanceIdentifierContext<? extends SchemaNode> context,
- final NormalizedNode data, final WriterParameters writerParameters) {
+ final NormalizedNode data, final WriterParameters writerParameters,
+ final ImmutableMap<String, Object> headers) {
this.context = context;
this.data = data;
this.writerParameters = writerParameters;
+ this.headers = requireNonNull(headers);
}
public NormalizedNodeContext(final InstanceIdentifierContext<? extends SchemaNode> context,
- final NormalizedNode data, final WriterParameters writerParameters, final Map<String, Object> headers) {
- this.context = context;
- this.data = data;
- this.writerParameters = writerParameters;
- this.headers = headers;
+ final NormalizedNode data, final WriterParameters writerParameters) {
+ this(context, data, writerParameters, ImmutableMap.of());
}
public NormalizedNodeContext(final InstanceIdentifierContext<? extends SchemaNode> context,
final NormalizedNode data) {
- this.context = context;
- this.data = data;
- // default writer parameters
- writerParameters = WriterParameters.EMPTY;
+ this(context, data, WriterParameters.EMPTY, ImmutableMap.of());
}
public NormalizedNodeContext(final InstanceIdentifierContext<? extends SchemaNode> context,
- final NormalizedNode data, final Map<String, Object> headers) {
- this.context = context;
- this.data = data;
- // default writer parameters
- writerParameters = WriterParameters.EMPTY;
- this.headers = headers;
+ final NormalizedNode data, final ImmutableMap<String, Object> headers) {
+ this(context, data, WriterParameters.EMPTY, headers);
}
public InstanceIdentifierContext<? extends SchemaNode> getInstanceIdentifierContext() {
*
* @return map of headers
*/
- public Map<String, Object> getNewHeaders() {
+ public ImmutableMap<String, Object> getNewHeaders() {
return headers;
}
}
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.base.Throwables;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.FluentFuture;
public NormalizedNodeContext getModules(final UriInfo uriInfo) {
final MapNode allModuleMap = makeModuleMapNode(controllerContext.getAllModules());
- final EffectiveModelContext schemaContext = this.controllerContext.getGlobalSchema();
+ final EffectiveModelContext schemaContext = controllerContext.getGlobalSchema();
final Module restconfModule = getRestconfModule();
- final DataSchemaNode modulesSchemaNode = this.controllerContext.getRestconfModuleRestConfSchemaNode(
+ final DataSchemaNode modulesSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode(
restconfModule, Draft02.RestConfModule.MODULES_CONTAINER_SCHEMA_NODE);
checkState(modulesSchemaNode instanceof ContainerSchemaNode);
}
final InstanceIdentifierContext<?> mountPointIdentifier =
- this.controllerContext.toMountPointIdentifier(identifier);
+ controllerContext.toMountPointIdentifier(identifier);
final DOMMountPoint mountPoint = mountPointIdentifier.getMountPoint();
final MapNode mountPointModulesMap = makeModuleMapNode(controllerContext.getAllModules(mountPoint));
final Module restconfModule = getRestconfModule();
- final DataSchemaNode modulesSchemaNode = this.controllerContext.getRestconfModuleRestConfSchemaNode(
+ final DataSchemaNode modulesSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode(
restconfModule, Draft02.RestConfModule.MODULES_CONTAINER_SCHEMA_NODE);
checkState(modulesSchemaNode instanceof ContainerSchemaNode);
return new NormalizedNodeContext(
new InstanceIdentifierContext<>(null, modulesSchemaNode, mountPoint,
- this.controllerContext.getGlobalSchema()),
+ controllerContext.getGlobalSchema()),
moduleContainerBuilder.build(), QueryParametersParser.parseWriterParameters(uriInfo));
}
final EffectiveModelContext schemaContext;
if (identifier.contains(ControllerContext.MOUNT)) {
final InstanceIdentifierContext<?> mountPointIdentifier =
- this.controllerContext.toMountPointIdentifier(identifier);
+ controllerContext.toMountPointIdentifier(identifier);
mountPoint = mountPointIdentifier.getMountPoint();
- module = this.controllerContext.findModuleByNameAndRevision(mountPoint, nameRev.getKey(),
+ module = controllerContext.findModuleByNameAndRevision(mountPoint, nameRev.getKey(),
nameRev.getValue());
schemaContext = modelContext(mountPoint);
} else {
- module = this.controllerContext.findModuleByNameAndRevision(nameRev.getKey(), nameRev.getValue());
- schemaContext = this.controllerContext.getGlobalSchema();
+ module = controllerContext.findModuleByNameAndRevision(nameRev.getKey(), nameRev.getValue());
+ schemaContext = controllerContext.getGlobalSchema();
}
if (module == null) {
final Set<Module> modules = Collections.singleton(module);
final MapNode moduleMap = makeModuleMapNode(modules);
- final DataSchemaNode moduleSchemaNode = this.controllerContext
+ final DataSchemaNode moduleSchemaNode = controllerContext
.getRestconfModuleRestConfSchemaNode(restconfModule, Draft02.RestConfModule.MODULE_LIST_SCHEMA_NODE);
checkState(moduleSchemaNode instanceof ListSchemaNode);
@Override
@Deprecated
public NormalizedNodeContext getAvailableStreams(final UriInfo uriInfo) {
- final EffectiveModelContext schemaContext = this.controllerContext.getGlobalSchema();
+ final EffectiveModelContext schemaContext = controllerContext.getGlobalSchema();
final Set<String> availableStreams = Notificator.getStreamNames();
final Module restconfModule = getRestconfModule();
- final DataSchemaNode streamSchemaNode = this.controllerContext
+ final DataSchemaNode streamSchemaNode = controllerContext
.getRestconfModuleRestConfSchemaNode(restconfModule, Draft02.RestConfModule.STREAM_LIST_SCHEMA_NODE);
checkState(streamSchemaNode instanceof ListSchemaNode);
listStreamsBuilder.withChild(toStreamEntryNode(streamName, streamSchemaNode));
}
- final DataSchemaNode streamsContainerSchemaNode = this.controllerContext.getRestconfModuleRestConfSchemaNode(
+ final DataSchemaNode streamsContainerSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode(
restconfModule, Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
checkState(streamsContainerSchemaNode instanceof ContainerSchemaNode);
}
final InstanceIdentifierContext<?> mountPointIdentifier =
- this.controllerContext.toMountPointIdentifier(identifier);
+ controllerContext.toMountPointIdentifier(identifier);
final DOMMountPoint mountPoint = mountPointIdentifier.getMountPoint();
return OperationsResourceUtils.contextForModelContext(modelContext(mountPoint), mountPoint);
}
private Module getRestconfModule() {
- final Module restconfModule = this.controllerContext.getRestconfModule();
+ final Module restconfModule = controllerContext.getRestconfModule();
if (restconfModule == null) {
LOG.debug("ietf-restconf module was not found.");
throw new RestconfDocumentedException("ietf-restconf module was not found.", ErrorType.APPLICATION,
throw new RestconfDocumentedException(msg, ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED);
}
} else {
- response = this.broker.invokeRpc(schema.getQName(), input);
+ response = broker.invokeRpc(schema.getQName(), input);
}
- schemaContext = this.controllerContext.getGlobalSchema();
+ schemaContext = controllerContext.getGlobalSchema();
}
final DOMRpcResult result = checkRpcResponse(response);
final EffectiveModelContext schemaContext;
if (identifier.contains(ControllerContext.MOUNT)) {
// mounted RPC call - look up mount instance.
- final InstanceIdentifierContext<?> mountPointId = this.controllerContext.toMountPointIdentifier(identifier);
+ final InstanceIdentifierContext<?> mountPointId = controllerContext.toMountPointIdentifier(identifier);
mountPoint = mountPointId.getMountPoint();
schemaContext = modelContext(mountPoint);
final int startOfRemoteRpcName =
} else if (identifier.indexOf('/') == CHAR_NOT_FOUND) {
identifierEncoded = identifier;
mountPoint = null;
- schemaContext = this.controllerContext.getGlobalSchema();
+ schemaContext = controllerContext.getGlobalSchema();
} else {
LOG.debug("Identifier {} cannot contain slash character (/).", identifier);
throw new RestconfDocumentedException(String.format("Identifier %n%s%ncan\'t contain slash character (/).%n"
final String identifierDecoded = ControllerContext.urlPathArgDecode(identifierEncoded);
final RpcDefinition rpc;
if (mountPoint == null) {
- rpc = this.controllerContext.getRpcDefinition(identifierDecoded);
+ rpc = controllerContext.getRpcDefinition(identifierDecoded);
} else {
rpc = findRpc(modelContext(mountPoint), identifierDecoded);
}
}
response = mountRpcServices.get().invokeRpc(rpc.getQName(), input);
} else {
- response = this.broker.invokeRpc(rpc.getQName(), input);
+ response = broker.invokeRpc(rpc.getQName(), input);
}
final NormalizedNode result = checkRpcResponse(response).getResult();
NotificationOutputType outputType = null;
if (!pathIdentifier.isEmpty()) {
final String fullRestconfIdentifier =
- DATA_SUBSCR + this.controllerContext.toFullRestconfIdentifier(pathIdentifier, null);
+ DATA_SUBSCR + controllerContext.toFullRestconfIdentifier(pathIdentifier, null);
LogicalDatastoreType datastore =
parseEnumTypeParameter(value, LogicalDatastoreType.class, DATASTORE_PARAM_NAME);
}
}
- final InstanceIdentifierContext<?> iiWithData = this.controllerContext.toInstanceIdentifier(identifier);
+ final InstanceIdentifierContext<?> iiWithData = controllerContext.toInstanceIdentifier(identifier);
final DOMMountPoint mountPoint = iiWithData.getMountPoint();
NormalizedNode data = null;
final YangInstanceIdentifier normalizedII = iiWithData.getInstanceIdentifier();
if (mountPoint != null) {
- data = this.broker.readConfigurationData(mountPoint, normalizedII, withDefa);
+ data = broker.readConfigurationData(mountPoint, normalizedII, withDefa);
} else {
- data = this.broker.readConfigurationData(normalizedII, withDefa);
+ data = broker.readConfigurationData(normalizedII, withDefa);
}
if (data == null) {
throw dataMissing(identifier);
@Override
public NormalizedNodeContext readOperationalData(final String identifier, final UriInfo uriInfo) {
- final InstanceIdentifierContext<?> iiWithData = this.controllerContext.toInstanceIdentifier(identifier);
+ final InstanceIdentifierContext<?> iiWithData = controllerContext.toInstanceIdentifier(identifier);
final DOMMountPoint mountPoint = iiWithData.getMountPoint();
NormalizedNode data = null;
final YangInstanceIdentifier normalizedII = iiWithData.getInstanceIdentifier();
if (mountPoint != null) {
- data = this.broker.readOperationalData(mountPoint, normalizedII);
+ data = broker.readOperationalData(mountPoint, normalizedII);
} else {
- data = this.broker.readOperationalData(normalizedII);
+ data = broker.readOperationalData(normalizedII);
}
if (data == null) {
throw dataMissing(identifier);
while (true) {
if (mountPoint != null) {
- result = this.broker.commitMountPointDataPut(mountPoint, normalizedII, payload.getData(), insert,
+ result = broker.commitMountPointDataPut(mountPoint, normalizedII, payload.getData(), insert,
point);
} else {
- result = this.broker.commitConfigurationDataPut(this.controllerContext.getGlobalSchema(), normalizedII,
+ result = broker.commitConfigurationDataPut(controllerContext.getGlobalSchema(), normalizedII,
payload.getData(), insert, point);
}
FluentFuture<? extends CommitInfo> future;
if (mountPoint != null) {
- future = this.broker.commitConfigurationDataPost(mountPoint, normalizedII, payload.getData(), insert,
+ future = broker.commitConfigurationDataPost(mountPoint, normalizedII, payload.getData(), insert,
point);
} else {
- future = this.broker.commitConfigurationDataPost(this.controllerContext.getGlobalSchema(), normalizedII,
+ future = broker.commitConfigurationDataPost(controllerContext.getGlobalSchema(), normalizedII,
payload.getData(), insert, point);
}
final UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
uriBuilder.path("config");
try {
- uriBuilder.path(this.controllerContext.toFullRestconfIdentifier(normalizedII, mountPoint));
+ uriBuilder.path(controllerContext.toFullRestconfIdentifier(normalizedII, mountPoint));
} catch (final Exception e) {
LOG.info("Location for instance identifier {} was not created", normalizedII, e);
return null;
@Override
public Response deleteConfigurationData(final String identifier) {
- final InstanceIdentifierContext<?> iiWithData = this.controllerContext.toInstanceIdentifier(identifier);
+ final InstanceIdentifierContext<?> iiWithData = controllerContext.toInstanceIdentifier(identifier);
final DOMMountPoint mountPoint = iiWithData.getMountPoint();
final YangInstanceIdentifier normalizedII = iiWithData.getInstanceIdentifier();
final FluentFuture<? extends CommitInfo> future;
if (mountPoint != null) {
- future = this.broker.commitConfigurationDataDelete(mountPoint, normalizedII);
+ future = broker.commitConfigurationDataDelete(mountPoint, normalizedII);
} else {
- future = this.broker.commitConfigurationDataDelete(normalizedII);
+ future = broker.commitConfigurationDataDelete(normalizedII);
}
try {
NodeIdentifier.create(QName.create("subscribe:to:notification", "2016-10-28", "location")));
// prepare new header with location
- final Map<String, Object> headers = new HashMap<>();
- headers.put("Location", response);
-
- return new NormalizedNodeContext(iid, builder.build(), headers);
+ return new NormalizedNodeContext(iid, builder.build(), ImmutableMap.of("Location", response));
}
final String msg = "Bad type of notification of sal-remote";
}
for (final NotificationListenerAdapter listener : listeners) {
- this.broker.registerToListenNotification(listener);
+ broker.registerToListenNotification(listener);
listener.setQueryParams(start, Optional.ofNullable(stop), Optional.ofNullable(filter), false, false);
}
ErrorType.APPLICATION, ErrorTag.MISSING_ATTRIBUTE);
}
- this.broker.registerToListenDataChanges(datastore, scope, listener);
+ broker.registerToListenDataChanges(datastore, scope, listener);
final UriBuilder uriBuilder = uriInfo.getAbsolutePathBuilder();
}
try {
- return this.broker.patchConfigurationDataWithinTransaction(context);
+ return broker.patchConfigurationDataWithinTransaction(context);
} catch (final Exception e) {
LOG.debug("Patch transaction failed", e);
throw new RestconfDocumentedException(e.getMessage(), e);
}
try {
- return this.broker.patchConfigurationDataWithinTransaction(context);
+ return broker.patchConfigurationDataWithinTransaction(context);
} catch (final Exception e) {
LOG.debug("Patch transaction failed", e);
throw new RestconfDocumentedException(e.getMessage(), e);
private MapNode makeModuleMapNode(final Collection<? extends Module> modules) {
requireNonNull(modules);
final Module restconfModule = getRestconfModule();
- final DataSchemaNode moduleSchemaNode = this.controllerContext
+ final DataSchemaNode moduleSchemaNode = controllerContext
.getRestconfModuleRestConfSchemaNode(restconfModule, Draft02.RestConfModule.MODULE_LIST_SCHEMA_NODE);
checkState(moduleSchemaNode instanceof ListSchemaNode);