2 * Copyright © 2022 Orange, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.transportpce.pce.gnpy.consumer;
10 import java.io.IOException;
11 import java.io.InputStream;
12 import java.lang.annotation.Annotation;
13 import java.lang.reflect.Type;
14 import javax.ws.rs.WebApplicationException;
15 import javax.ws.rs.core.MediaType;
16 import javax.ws.rs.core.MultivaluedMap;
17 import javax.ws.rs.ext.MessageBodyReader;
18 import org.opendaylight.transportpce.common.converter.JsonStringConverter;
19 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.Result;
20 import org.opendaylight.yangtools.yang.common.QName;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
22 import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactorySupplier;
24 public class ResultMessageBodyReader implements MessageBodyReader<Result> {
25 private final JsonStringConverter<Result> converter;
26 private final YangInstanceIdentifier yangId;
28 public ResultMessageBodyReader(JsonStringConverter<Result> converter) {
29 QName pathQname = Result.QNAME;
30 yangId = YangInstanceIdentifier.of(pathQname);
31 this.converter = converter;
35 @SuppressWarnings("java:S1872")
36 public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
37 return "org.opendaylight.yang.gen.v1.gnpy.path.rev220615.Result"
38 .equals(type.getName());
42 public Result readFrom(Class<Result> type, Type genericType, Annotation[] annotations,
43 MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
44 throws IOException, WebApplicationException {
45 return converter.createDataObjectFromInputStream(yangId, entityStream,
46 JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02);