Camelize the name of metric type for REST API
Change-Id: Ib44be594e4021ed36e5069ec0bce8c17dd044706
Showing
1 changed file
with
12 additions
and
3 deletions
... | @@ -17,6 +17,7 @@ package org.onosproject.cpman.rest; | ... | @@ -17,6 +17,7 @@ package org.onosproject.cpman.rest; |
17 | 17 | ||
18 | import com.fasterxml.jackson.databind.node.ArrayNode; | 18 | import com.fasterxml.jackson.databind.node.ArrayNode; |
19 | import com.fasterxml.jackson.databind.node.ObjectNode; | 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
20 | +import org.apache.commons.lang3.StringUtils; | ||
20 | import org.onosproject.cluster.ClusterService; | 21 | import org.onosproject.cluster.ClusterService; |
21 | import org.onosproject.cluster.NodeId; | 22 | import org.onosproject.cluster.NodeId; |
22 | import org.onosproject.cpman.ControlLoad; | 23 | import org.onosproject.cpman.ControlLoad; |
... | @@ -249,7 +250,7 @@ public class ControlMetricsWebResource extends AbstractWebResource { | ... | @@ -249,7 +250,7 @@ public class ControlMetricsWebResource extends AbstractWebResource { |
249 | ObjectNode metricNode = mapper().createObjectNode(); | 250 | ObjectNode metricNode = mapper().createObjectNode(); |
250 | ControlLoad load = service.getLocalLoad(type, Optional.ofNullable(null)); | 251 | ControlLoad load = service.getLocalLoad(type, Optional.ofNullable(null)); |
251 | if (load != null) { | 252 | if (load != null) { |
252 | - metricNode.set(type.toString().toLowerCase(), codec(ControlLoad.class) | 253 | + metricNode.set(toCamelCase(type.toString(), true), codec(ControlLoad.class) |
253 | .encode(service.getLocalLoad(type, Optional.ofNullable(null)), this)); | 254 | .encode(service.getLocalLoad(type, Optional.ofNullable(null)), this)); |
254 | metricsNode.add(metricNode); | 255 | metricsNode.add(metricNode); |
255 | } | 256 | } |
... | @@ -259,7 +260,7 @@ public class ControlMetricsWebResource extends AbstractWebResource { | ... | @@ -259,7 +260,7 @@ public class ControlMetricsWebResource extends AbstractWebResource { |
259 | ObjectNode metricNode = mapper().createObjectNode(); | 260 | ObjectNode metricNode = mapper().createObjectNode(); |
260 | ControlLoad load = service.getLocalLoad(type, Optional.of(did)); | 261 | ControlLoad load = service.getLocalLoad(type, Optional.of(did)); |
261 | if (load != null) { | 262 | if (load != null) { |
262 | - metricNode.set(type.toString().toLowerCase(), | 263 | + metricNode.set(toCamelCase(type.toString(), true), |
263 | codec(ControlLoad.class).encode(load, this)); | 264 | codec(ControlLoad.class).encode(load, this)); |
264 | metricsNode.add(metricNode); | 265 | metricsNode.add(metricNode); |
265 | } | 266 | } |
... | @@ -269,7 +270,7 @@ public class ControlMetricsWebResource extends AbstractWebResource { | ... | @@ -269,7 +270,7 @@ public class ControlMetricsWebResource extends AbstractWebResource { |
269 | ObjectNode metricNode = mapper().createObjectNode(); | 270 | ObjectNode metricNode = mapper().createObjectNode(); |
270 | ControlLoad load = service.getLocalLoad(type, name); | 271 | ControlLoad load = service.getLocalLoad(type, name); |
271 | if (load != null) { | 272 | if (load != null) { |
272 | - metricNode.set(type.toString().toLowerCase(), | 273 | + metricNode.set(toCamelCase(type.toString(), true), |
273 | codec(ControlLoad.class).encode(load, this)); | 274 | codec(ControlLoad.class).encode(load, this)); |
274 | metricsNode.add(metricNode); | 275 | metricsNode.add(metricNode); |
275 | } | 276 | } |
... | @@ -278,4 +279,12 @@ public class ControlMetricsWebResource extends AbstractWebResource { | ... | @@ -278,4 +279,12 @@ public class ControlMetricsWebResource extends AbstractWebResource { |
278 | 279 | ||
279 | return metricsNode; | 280 | return metricsNode; |
280 | } | 281 | } |
282 | + | ||
283 | + private String toCamelCase(String value, boolean startWithLowerCase) { | ||
284 | + String[] strings = StringUtils.split(value.toLowerCase(), "_"); | ||
285 | + for (int i = startWithLowerCase ? 1 : 0; i < strings.length; i++) { | ||
286 | + strings[i] = StringUtils.capitalize(strings[i]); | ||
287 | + } | ||
288 | + return StringUtils.join(strings); | ||
289 | + } | ||
281 | } | 290 | } | ... | ... |
-
Please register or login to post a comment