Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.codec.impl; |
| 17 | |
| 18 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 19 | import org.onosproject.app.ApplicationService; |
| 20 | import org.onosproject.codec.CodecContext; |
| 21 | import org.onosproject.codec.JsonCodec; |
| 22 | import org.onosproject.core.Application; |
| 23 | |
| 24 | import static com.google.common.base.Preconditions.checkNotNull; |
| 25 | |
| 26 | /** |
| 27 | * Application JSON codec. |
| 28 | */ |
Ray Milkey | 540b2ce | 2015-02-04 17:50:20 -0800 | [diff] [blame] | 29 | public final class ApplicationCodec extends JsonCodec<Application> { |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 30 | |
| 31 | @Override |
| 32 | public ObjectNode encode(Application app, CodecContext context) { |
| 33 | checkNotNull(app, "Application cannot be null"); |
Ray Milkey | 3078fc0 | 2015-05-06 16:14:14 -0700 | [diff] [blame] | 34 | ApplicationService service = context.getService(ApplicationService.class); |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 35 | return context.mapper().createObjectNode() |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 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()) |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 41 | .put("permissions", app.permissions().toString()) // FIXME: change to an array |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 42 | .put("featuresRepo", app.featuresRepo().isPresent() ? |
Thomas Vachuska | ebf5e54 | 2015-02-03 19:38:13 -0800 | [diff] [blame] | 43 | app.featuresRepo().get().toString() : "") |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 44 | .put("features", app.features().toString()) // FIXME: change to an array |
| 45 | .put("requiredApps", app.requiredApps().toString()) // FIXME: change to an array |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 46 | .put("state", service.getState(app.id()).toString()); |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | } |