Thomas Vachuska | f758255 | 2015-05-14 10:13:46 -0700 | [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 | |
| 17 | package org.onosproject.cord.gui; |
| 18 | |
| 19 | import javax.ws.rs.GET; |
| 20 | import javax.ws.rs.Path; |
Simon Hunt | 3e59c60 | 2015-05-18 15:29:42 -0700 | [diff] [blame] | 21 | import javax.ws.rs.PathParam; |
| 22 | import javax.ws.rs.Produces; |
| 23 | import javax.ws.rs.core.MediaType; |
Thomas Vachuska | f758255 | 2015-05-14 10:13:46 -0700 | [diff] [blame] | 24 | import javax.ws.rs.core.Response; |
| 25 | |
| 26 | /** |
| 27 | * Web resource to use as the GUI back-end and as a proxy to XOS REST API. |
| 28 | */ |
| 29 | @Path("") |
| 30 | public class CordWebResource { |
| 31 | |
Simon Hunt | a29c87b | 2015-05-21 09:56:19 -0700 | [diff] [blame] | 32 | @GET |
| 33 | @Produces(MediaType.APPLICATION_JSON) |
Simon Hunt | c296d2c | 2015-06-08 12:54:57 -0700 | [diff] [blame] | 34 | @Path("login/{email}") |
| 35 | public Response login(@PathParam("email") String email) { |
| 36 | return Response.ok(CordModelCache.INSTANCE.jsonLogin(email)).build(); |
| 37 | } |
| 38 | |
| 39 | @GET |
| 40 | @Produces(MediaType.APPLICATION_JSON) |
Simon Hunt | a29c87b | 2015-05-21 09:56:19 -0700 | [diff] [blame] | 41 | @Path("dashboard") |
| 42 | public Response dashboard() { |
Simon Hunt | 09a32db | 2015-05-21 15:00:42 -0700 | [diff] [blame] | 43 | return Response.ok(CordModelCache.INSTANCE.jsonDashboard()).build(); |
Simon Hunt | a29c87b | 2015-05-21 09:56:19 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Simon Hunt | 09a32db | 2015-05-21 15:00:42 -0700 | [diff] [blame] | 46 | @GET |
| 47 | @Produces(MediaType.APPLICATION_JSON) |
| 48 | @Path("bundle") |
| 49 | public Response bundle() { |
| 50 | return Response.ok(CordModelCache.INSTANCE.jsonBundle()).build(); |
| 51 | } |
| 52 | |
| 53 | @GET |
| 54 | @Produces(MediaType.APPLICATION_JSON) |
| 55 | @Path("users") |
| 56 | public Response users() { |
| 57 | return Response.ok(CordModelCache.INSTANCE.jsonUsers()).build(); |
| 58 | } |
| 59 | |
Simon Hunt | 09a32db | 2015-05-21 15:00:42 -0700 | [diff] [blame] | 60 | @GET |
| 61 | @Produces(MediaType.APPLICATION_JSON) |
Simon Hunt | c296d2c | 2015-06-08 12:54:57 -0700 | [diff] [blame] | 62 | @Path("logout") |
| 63 | public Response logout() { |
| 64 | return Response.ok(CordModelCache.INSTANCE.jsonLogout()).build(); |
Simon Hunt | c686c6a | 2015-06-05 14:33:30 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Simon Hunt | c296d2c | 2015-06-08 12:54:57 -0700 | [diff] [blame] | 67 | // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
| 68 | |
Simon Hunt | c686c6a | 2015-06-05 14:33:30 -0700 | [diff] [blame] | 69 | @GET |
| 70 | @Produces(MediaType.APPLICATION_JSON) |
Simon Hunt | 09a32db | 2015-05-21 15:00:42 -0700 | [diff] [blame] | 71 | @Path("bundle/{id}") |
Simon Hunt | 09a32db | 2015-05-21 15:00:42 -0700 | [diff] [blame] | 72 | public Response bundle(@PathParam("id") String bundleId) { |
| 73 | CordModelCache.INSTANCE.setCurrentBundle(bundleId); |
| 74 | return bundle(); |
| 75 | } |
Simon Hunt | 6c2555b | 2015-05-21 18:17:56 -0700 | [diff] [blame] | 76 | |
| 77 | @GET |
| 78 | @Produces(MediaType.APPLICATION_JSON) |
| 79 | @Path("users/{id}/apply/{func}/{param}/{value}") |
| 80 | public Response bundle(@PathParam("id") String userId, |
| 81 | @PathParam("func") String funcId, |
| 82 | @PathParam("param") String param, |
| 83 | @PathParam("value") String value) { |
| 84 | CordModelCache.INSTANCE.applyPerUserParam(userId, funcId, param, value); |
| 85 | return users(); |
| 86 | } |
Thomas Vachuska | f758255 | 2015-05-14 10:13:46 -0700 | [diff] [blame] | 87 | } |