GUI -- Backend Java sorting of devices WIP.
Change-Id: I2df7efba3dfc0cff097bf5c6509849fa7ef438eb
Showing
1 changed file
with
25 additions
and
3 deletions
... | @@ -24,10 +24,13 @@ import org.onosproject.net.Device; | ... | @@ -24,10 +24,13 @@ import org.onosproject.net.Device; |
24 | import org.onosproject.net.device.DeviceService; | 24 | import org.onosproject.net.device.DeviceService; |
25 | import org.slf4j.Logger; | 25 | import org.slf4j.Logger; |
26 | 26 | ||
27 | +import javax.ws.rs.DefaultValue; | ||
27 | import javax.ws.rs.GET; | 28 | import javax.ws.rs.GET; |
28 | import javax.ws.rs.Path; | 29 | import javax.ws.rs.Path; |
29 | import javax.ws.rs.Produces; | 30 | import javax.ws.rs.Produces; |
31 | +import javax.ws.rs.QueryParam; | ||
30 | import javax.ws.rs.core.Response; | 32 | import javax.ws.rs.core.Response; |
33 | +import java.util.ArrayList; | ||
31 | 34 | ||
32 | import static org.slf4j.LoggerFactory.getLogger; | 35 | import static org.slf4j.LoggerFactory.getLogger; |
33 | 36 | ||
... | @@ -48,13 +51,32 @@ public class DeviceGuiResource extends BaseResource { | ... | @@ -48,13 +51,32 @@ public class DeviceGuiResource extends BaseResource { |
48 | // return list of devices | 51 | // return list of devices |
49 | @GET | 52 | @GET |
50 | @Produces("application/json") | 53 | @Produces("application/json") |
51 | - public Response getDevices() { | 54 | + public Response getDevices( |
55 | + @DefaultValue("none") @QueryParam("sortCol") String colId, | ||
56 | + @DefaultValue("none") @QueryParam("sortDir") String dir | ||
57 | + ) { | ||
52 | ObjectNode rootNode = mapper.createObjectNode(); | 58 | ObjectNode rootNode = mapper.createObjectNode(); |
53 | ArrayNode devices = mapper.createArrayNode(); | 59 | ArrayNode devices = mapper.createArrayNode(); |
54 | DeviceService service = get(DeviceService.class); | 60 | DeviceService service = get(DeviceService.class); |
55 | 61 | ||
56 | - for (Device dev: service.getDevices()) { | 62 | + // if no query parameters were given, get the data in whatever order |
57 | - devices.add(deviceJson(service, dev)); | 63 | + if (colId.equals("none") || dir.equals("none")) { |
64 | + for (Device dev : service.getDevices()) { | ||
65 | + devices.add(deviceJson(service, dev)); | ||
66 | + } | ||
67 | + } else { | ||
68 | + ArrayList<Device> sortedDevices = new ArrayList<>(); | ||
69 | + for (Device dev : service.getDevices()) { | ||
70 | + sortedDevices.add(dev); | ||
71 | + } | ||
72 | + // now sort the arrayList based on the query parameters | ||
73 | + // then put each item into the ArrayNode devices | ||
74 | + // (pass in each device to deviceJson) | ||
75 | + | ||
76 | + // at this point, the sortedDevices list will be sorted | ||
77 | + for (Device dev : sortedDevices) { | ||
78 | + devices.add(deviceJson(service, dev)); | ||
79 | + } | ||
58 | } | 80 | } |
59 | 81 | ||
60 | rootNode.set("devices", devices); | 82 | rootNode.set("devices", devices); | ... | ... |
-
Please register or login to post a comment