use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.
the class ControllerContext method toIdentifier.
private InstanceIdentifierContext<?> toIdentifier(final String restconfInstance, final boolean toMountPointIdentifier) {
checkPreconditions();
if (restconfInstance == null) {
return new InstanceIdentifierContext<>(YangInstanceIdentifier.empty(), globalSchema, null, globalSchema);
}
final List<String> pathArgs = urlPathArgsDecode(SLASH_SPLITTER.split(restconfInstance));
omitFirstAndLastEmptyString(pathArgs);
if (pathArgs.isEmpty()) {
return null;
}
final String first = pathArgs.iterator().next();
final String startModule = toModuleName(first);
if (startModule == null) {
throw new RestconfDocumentedException("First node in URI has to be in format \"moduleName:nodeName\"", ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
}
final InstanceIdentifierBuilder builder = YangInstanceIdentifier.builder();
final Collection<? extends Module> latestModule = globalSchema.findModules(startModule);
if (latestModule.isEmpty()) {
throw new RestconfDocumentedException("The module named '" + startModule + "' does not exist.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT);
}
final InstanceIdentifierContext<?> iiWithSchemaNode = collectPathArguments(builder, pathArgs, latestModule.iterator().next(), null, toMountPointIdentifier);
if (iiWithSchemaNode == null) {
throw new RestconfDocumentedException("URI has bad format", ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
}
return iiWithSchemaNode;
}
use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.
the class ControllerContext method addKeyValue.
private void addKeyValue(final HashMap<QName, Object> map, final DataSchemaNode node, final String uriValue, final DOMMountPoint mountPoint) {
checkArgument(node instanceof LeafSchemaNode);
final EffectiveModelContext schemaContext = mountPoint == null ? globalSchema : getModelContext(mountPoint);
final String urlDecoded = urlPathArgDecode(requireNonNull(uriValue));
TypeDefinition<?> typedef = ((LeafSchemaNode) node).getType();
final TypeDefinition<?> baseType = RestUtil.resolveBaseTypeFrom(typedef);
if (baseType instanceof LeafrefTypeDefinition) {
typedef = SchemaInferenceStack.ofInstantiatedPath(schemaContext, node.getPath()).resolveLeafref((LeafrefTypeDefinition) baseType);
}
final IllegalArgumentCodec<Object, Object> codec = RestCodec.from(typedef, mountPoint, this);
Object decoded = codec.deserialize(urlDecoded);
String additionalInfo = "";
if (decoded == null) {
if (typedef instanceof IdentityrefTypeDefinition) {
decoded = toQName(schemaContext, urlDecoded);
additionalInfo = "For key which is of type identityref it should be in format module_name:identity_name.";
}
}
if (decoded == null) {
throw new RestconfDocumentedException(uriValue + " from URI can't be resolved. " + additionalInfo, ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
}
map.put(node.getQName(), decoded);
}
use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.
the class RestconfImpl method isEqualUriAndPayloadKeyValues.
@VisibleForTesting
public static void isEqualUriAndPayloadKeyValues(final Map<QName, Object> uriKeyValues, final MapEntryNode payload, final List<QName> keyDefinitions) {
final Map<QName, Object> mutableCopyUriKeyValues = new HashMap<>(uriKeyValues);
for (final QName keyDefinition : keyDefinitions) {
final Object uriKeyValue = RestconfDocumentedException.throwIfNull(// should be caught during parsing URI to InstanceIdentifier
mutableCopyUriKeyValues.remove(keyDefinition), ErrorType.PROTOCOL, ErrorTag.DATA_MISSING, "Missing key %s in URI.", keyDefinition);
final Object dataKeyValue = payload.getIdentifier().getValue(keyDefinition);
if (!Objects.deepEquals(uriKeyValue, dataKeyValue)) {
final String errMsg = "The value '" + uriKeyValue + "' for key '" + keyDefinition.getLocalName() + "' specified in the URI doesn't match the value '" + dataKeyValue + "' specified in the message body. ";
throw new RestconfDocumentedException(errMsg, ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
}
}
}
use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.
the class RestconfImpl method deleteConfigurationData.
@Override
public Response deleteConfigurationData(final String 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 = broker.commitConfigurationDataDelete(mountPoint, normalizedII);
} else {
future = broker.commitConfigurationDataDelete(normalizedII);
}
try {
future.get();
} catch (final InterruptedException e) {
throw new RestconfDocumentedException(e.getMessage(), e);
} catch (final ExecutionException e) {
final Optional<Throwable> searchedException = Iterables.tryFind(Throwables.getCausalChain(e), Predicates.instanceOf(ModifiedNodeDoesNotExistException.class)).toJavaUtil();
if (searchedException.isPresent()) {
throw new RestconfDocumentedException("Data specified for delete doesn't exist.", ErrorType.APPLICATION, ErrorTag.DATA_MISSING, e);
}
throw RestconfDocumentedException.decodeAndThrow(e.getMessage(), Throwables.getCauseAs(e, TransactionCommitFailedException.class));
}
return Response.status(Status.OK).build();
}
use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.
the class RestconfImpl method getOperations.
@Override
@Deprecated
public NormalizedNodeContext getOperations(final String identifier, final UriInfo uriInfo) {
if (!identifier.contains(ControllerContext.MOUNT)) {
final String errMsg = "URI has bad format. If operations behind mount point should be showed, URI has to " + " end with " + ControllerContext.MOUNT;
LOG.debug("{} for {}", errMsg, identifier);
throw new RestconfDocumentedException(errMsg, ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
}
final InstanceIdentifierContext<?> mountPointIdentifier = controllerContext.toMountPointIdentifier(identifier);
final DOMMountPoint mountPoint = mountPointIdentifier.getMountPoint();
final var entry = OperationsResourceUtils.contextForModelContext(modelContext(mountPoint), mountPoint);
return new NormalizedNodeContext(entry.getKey(), entry.getValue());
}
Aggregations