dvaddire | 95c84ed | 2017-06-14 15:42:24 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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.ObjectMapper; |
| 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 20 | import org.onosproject.codec.CodecContext; |
| 21 | import org.onosproject.codec.JsonCodec; |
| 22 | import org.onosproject.net.intent.util.IntentMiniSummary; |
| 23 | |
| 24 | import static com.google.common.base.Preconditions.checkNotNull; |
| 25 | |
| 26 | /** |
| 27 | * Intent MiniSummary JSON codec. |
| 28 | */ |
| 29 | public class IntentMiniSummaryCodec extends JsonCodec<IntentMiniSummary> { |
| 30 | private static final String TOTAL = "total"; |
| 31 | private static final String INSTALLREQ = "installReq"; |
| 32 | private static final String COMPILING = "compiling"; |
| 33 | private static final String INSTALLING = "installing"; |
| 34 | private static final String INSTALLED = "installed"; |
| 35 | private static final String RECOMPILING = "recompiling"; |
| 36 | private static final String WITHDRAWREQ = "withdrawReq"; |
| 37 | private static final String WITHDRAWING = "withdrawing"; |
| 38 | private static final String WITHDRAWN = "withdrawn"; |
| 39 | private static final String FAILED = "failed"; |
| 40 | private static final String UNKNOWNSTATE = "unknownState"; |
| 41 | |
| 42 | @Override |
| 43 | public ObjectNode encode(IntentMiniSummary intentminisummary, CodecContext context) { |
| 44 | checkNotNull(intentminisummary, "intentminisummary cannot be null"); |
| 45 | ObjectMapper mapper = new ObjectMapper(); |
| 46 | ObjectNode result = mapper.createObjectNode() |
| 47 | .put(TOTAL, intentminisummary.getTotal()) |
| 48 | .put(INSTALLED, intentminisummary.getInstalled()) |
| 49 | .put(FAILED, intentminisummary.getFailed()) |
| 50 | .put(INSTALLREQ, intentminisummary.getInstallReq()) |
| 51 | .put(INSTALLING, intentminisummary.getInstalling()) |
| 52 | .put(COMPILING, intentminisummary.getCompiling()) |
| 53 | .put(RECOMPILING, intentminisummary.getRecompiling()) |
| 54 | .put(WITHDRAWREQ, intentminisummary.getWithdrawReq()) |
| 55 | .put(WITHDRAWING, intentminisummary.getWithdrawing()) |
| 56 | .put(WITHDRAWN, intentminisummary.getWithdrawn()) |
| 57 | .put(UNKNOWNSTATE, intentminisummary.getUnknownState()); |
| 58 | return result; |
| 59 | } |
| 60 | } |