import java.nio.charset.StandardCharsets;
import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.common.patch.PatchContext;
import org.opendaylight.restconf.common.patch.PatchEntity;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.patch.rev170222.yang.patch.yang.patch.Edit.Operation;
}
@Override
- PatchContext toPatchContext(final ResourceContext resource, final InputStream inputStream) throws IOException {
+ PatchContext toPatchContext(final ResourceContext resource, final InputStream inputStream)
+ throws IOException, ServerException {
try (var jsonReader = new JsonReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
final var patchId = new AtomicReference<String>();
final var resultList = read(jsonReader, resource, patchId);
}
private static ImmutableList<PatchEntity> read(final JsonReader in, final @NonNull ResourceContext resource,
- final AtomicReference<String> patchId) throws IOException {
+ final AtomicReference<String> patchId) throws IOException, ServerException {
final var edits = ImmutableList.<PatchEntity>builder();
final var edit = new PatchEdit();
private static void parseByName(final @NonNull String name, final @NonNull PatchEdit edit,
final @NonNull JsonReader in, final @NonNull ResourceContext resource,
final @NonNull Builder<PatchEntity> resultCollection, final @NonNull AtomicReference<String> patchId)
- throws IOException {
+ throws IOException, ServerException {
switch (name) {
case "edit" -> {
if (in.peek() == JsonToken.BEGIN_ARRAY) {
// Read one patch edit object from JSON input
private static void readEditDefinition(final @NonNull PatchEdit edit, final @NonNull JsonReader in,
- final @NonNull ResourceContext resource) throws IOException {
+ final @NonNull ResourceContext resource) throws IOException, ServerException {
String deferredValue = null;
in.beginObject();
* Prepare PatchEntity from PatchEdit instance when it satisfies conditions, otherwise throws exception.
* @param edit Instance of PatchEdit
* @return PatchEntity Patch entity
+ * @throws ServerException if the {@link PatchEdit} is not consistent
*/
- private static PatchEntity prepareEditOperation(final @NonNull PatchEdit edit) {
+ private static PatchEntity prepareEditOperation(final @NonNull PatchEdit edit) throws ServerException {
if (edit.getOperation() != null && edit.getTargetSchemaNode() != null
&& checkDataPresence(edit.getOperation(), edit.getData() != null)) {
if (!requiresValue(edit.getOperation())) {
return new PatchEntity(edit.getId(), edit.getOperation(), targetNode, edit.getData());
}
- throw new RestconfDocumentedException("Error parsing input", ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE);
+ throw new ServerException(ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE, "Error parsing input");
}
/**