blob: 5be664facfb3fff03192e4825fef08ad310c6f29 [file] [log] [blame]
Daniel Park3a06c522016-01-28 20:51:12 +09001/*
2 * Copyright 2016 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
sangho0c2a3da2016-02-16 13:39:07 +090016package org.onosproject.openstacknetworking.web;
Daniel Park3a06c522016-01-28 20:51:12 +090017
18import com.fasterxml.jackson.databind.JsonNode;
19import com.fasterxml.jackson.databind.node.ObjectNode;
20import org.onosproject.codec.CodecContext;
21import org.onosproject.codec.JsonCodec;
sangho0c2a3da2016-02-16 13:39:07 +090022import org.onosproject.openstacknetworking.OpenstackRouterInterface;
Daniel Park3a06c522016-01-28 20:51:12 +090023import org.slf4j.Logger;
24import org.slf4j.LoggerFactory;
25import static com.google.common.base.Preconditions.checkNotNull;
26/**
27 * Implementation of the OpenstackRouterInterface Codec.
28 */
29public class OpenstackRouterInterfaceCodec extends JsonCodec<OpenstackRouterInterface> {
sangho0c2a3da2016-02-16 13:39:07 +090030 private final Logger log = LoggerFactory.getLogger(getClass());
Daniel Park3a06c522016-01-28 20:51:12 +090031
32 private static final String ID = "id";
33 private static final String TENANT_ID = "tenant_id";
34 private static final String SUBNET_ID = "subnet_id";
35 private static final String PORT_ID = "port_id";
36
37 /**
38 * Decodes the OpenstackRouterInterface.
39 *
40 * @param json JSON to decode
41 * @param context decoding context
42 * @return OpenstackRouterInterface
43 */
44 @Override
45 public OpenstackRouterInterface decode(ObjectNode json, CodecContext context) {
46 if (json == null || !json.isObject()) {
47 return null;
48 }
49 JsonNode routerIfInfo = json;
50
51 String id = checkNotNull(routerIfInfo.path(ID).asText());
52 String tenantId = checkNotNull(routerIfInfo.path(TENANT_ID).asText());
53 String subnetId = checkNotNull(routerIfInfo.path(SUBNET_ID).asText());
54 String portId = checkNotNull(routerIfInfo.path(PORT_ID).asText());
55
56 OpenstackRouterInterface.Builder osBuilder = new OpenstackRouterInterface.Builder()
57 .id(id)
58 .tenantId(tenantId)
59 .subnetId(subnetId)
60 .portId(portId);
61
62 return osBuilder.build();
63 }
64}