blob: a09c0bdbf75d285e8277dcd8886ae15cfe7bdc0e [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");
Ray Milkey3078fc02015-05-06 16:14:14 -070034 ApplicationService service = context.getService(ApplicationService.class);
Thomas Vachuska761f0042015-11-11 19:10:17 -080035 return context.mapper().createObjectNode()
Thomas Vachuska02aeb032015-01-06 22:36:30 -080036 .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())
Thomas Vachuska761f0042015-11-11 19:10:17 -080041 .put("permissions", app.permissions().toString()) // FIXME: change to an array
Thomas Vachuska02aeb032015-01-06 22:36:30 -080042 .put("featuresRepo", app.featuresRepo().isPresent() ?
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080043 app.featuresRepo().get().toString() : "")
Thomas Vachuska761f0042015-11-11 19:10:17 -080044 .put("features", app.features().toString()) // FIXME: change to an array
45 .put("requiredApps", app.requiredApps().toString()) // FIXME: change to an array
Thomas Vachuska02aeb032015-01-06 22:36:30 -080046 .put("state", service.getState(app.id()).toString());
Thomas Vachuska02aeb032015-01-06 22:36:30 -080047 }
48
49}