1 package org.openkilda.integration.converter;
3 import com.fasterxml.jackson.core.JsonParseException;
4 import com.fasterxml.jackson.databind.JsonMappingException;
6 import java.io.IOException;
7 import java.util.ArrayList;
8 import java.util.Collections;
11 import org.json.simple.JSONObject;
12 import org.json.simple.JSONValue;
22 public static List<PortInfo>
toPortsInfo(
final JSONObject jsonObject,
final String switchId)
23 throws JsonParseException, JsonMappingException, IOException {
24 List<PortInfo> ports =
new ArrayList<PortInfo>();
25 if (jsonObject != null) {
26 Object
object = jsonObject.get(switchId);
28 String val = JSONValue.toJSONString(
object);
32 List<PortDetail> portDetailList = portsDetail.
getPortDetail();
33 if (portDetailList != null && !portDetailList.isEmpty()) {
34 ports = getPortsInfo(portDetailList, switchId, ports);
41 private static List<PortInfo> getPortsInfo(
final List<PortDetail> portsDetail,
42 final String key,
final List<PortInfo> switchPortsInfoList) {
45 if (!portDetail.getPortNumber().equalsIgnoreCase(
"local")) {
46 PortInfo info = setPortInfo(key, portDetail);
47 switchPortsInfoList.add(info);
51 Collections.sort(switchPortsInfoList);
52 return switchPortsInfoList;
55 private static PortInfo setPortInfo(
final String key,
final PortDetail portDetail) {
56 PortInfo portInfo =
new PortInfo();
57 StringBuilder currentFeatures =
new StringBuilder();
59 if (portDetail.getCurrentFeatures() != null
60 && portDetail.getCurrentFeatures().size() > 0) {
62 for (
int i = 0;
i < portDetail.getCurrentFeatures().size();
i++) {
63 if (currentFeatures.length() == 0) {
64 currentFeatures = currentFeatures.append(portDetail
65 .getCurrentFeatures().
get(
i));
67 currentFeatures = currentFeatures.append(
","+portDetail
68 .getCurrentFeatures().
get(
i));
71 portInfo.setInterfacetype(currentFeatures.toString());
73 portInfo.setSwitchName(key);
74 portInfo.setPortNumber(portDetail.getPortNumber());
75 portInfo.setPortName(portDetail.getName());
76 if (portDetail.getState() != null && !portDetail.getState().isEmpty()) {
77 portInfo.setStatus(portDetail.getState().get(0));
static List< PortInfo > toPortsInfo(final JSONObject jsonObject, final String switchId)
static< T > T toObject(final String data, final Class< T > objClass)
List< PortDetail > getPortDetail()