blob: 4812154934dcf5af7f3315b79b90cbccffb35543 [file] [log] [blame]
Thomas Vachuska02aeb032015-01-06 22:36:30 -08001/*
2 * Copyright 2015 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 */
16package org.onosproject.codec.impl;
17
18import com.fasterxml.jackson.databind.node.ObjectNode;
19import org.onosproject.app.ApplicationService;
20import org.onosproject.codec.CodecContext;
21import org.onosproject.codec.JsonCodec;
22import org.onosproject.core.Application;
23
24import static com.google.common.base.Preconditions.checkNotNull;
25
26/**
27 * Application JSON codec.
28 */
Ray Milkey540b2ce2015-02-04 17:50:20 -080029public final class ApplicationCodec extends JsonCodec<Application> {
Thomas Vachuska02aeb032015-01-06 22:36:30 -080030
31 @Override
32 public ObjectNode encode(Application app, CodecContext context) {
33 checkNotNull(app, "Application cannot be null");
34 ApplicationService service = context.get(ApplicationService.class);
35 ObjectNode result = context.mapper().createObjectNode()
36 .put("name", app.id().name())
37 .put("id", app.id().id())
38 .put("version", app.version().toString())
39 .put("description", app.description())
40 .put("origin", app.origin())
41 .put("permissions", app.permissions().toString())
42 .put("featuresRepo", app.featuresRepo().isPresent() ?
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080043 app.featuresRepo().get().toString() : "")
Thomas Vachuska02aeb032015-01-06 22:36:30 -080044 .put("features", app.features().toString())
45 .put("state", service.getState(app.id()).toString());
46 return result;
47 }
48
49}