blob: 760147854141622d426c85e0d990ea0d07e30229 [file] [log] [blame]
Thomas Vachuska530e52a2015-05-06 19:51:32 -07001/*
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 */
16package org.onosproject.ui.impl;
17
18import com.sun.jersey.multipart.FormDataParam;
19import org.onlab.rest.BaseResource;
20import org.onosproject.app.ApplicationAdminService;
Jian Li97d6b2d2016-01-20 10:13:43 -080021import org.onosproject.core.Application;
22import org.onosproject.core.ApplicationId;
Thomas Vachuska530e52a2015-05-06 19:51:32 -070023
24import javax.ws.rs.Consumes;
Jian Li97d6b2d2016-01-20 10:13:43 -080025import javax.ws.rs.GET;
Thomas Vachuska530e52a2015-05-06 19:51:32 -070026import javax.ws.rs.POST;
27import javax.ws.rs.Path;
Jian Li97d6b2d2016-01-20 10:13:43 -080028import javax.ws.rs.PathParam;
29import javax.ws.rs.Produces;
Thomas Vachuska530e52a2015-05-06 19:51:32 -070030import javax.ws.rs.core.MediaType;
31import javax.ws.rs.core.Response;
32import java.io.IOException;
33import java.io.InputStream;
34
35/**
36 * Application upload resource.
37 */
38@Path("applications")
39public class ApplicationResource extends BaseResource {
40
41 @Path("upload")
42 @POST
43 @Consumes(MediaType.MULTIPART_FORM_DATA)
44 public Response upload(@FormDataParam("file") InputStream stream) throws IOException {
Bri Prebilic Cole522e7562015-06-22 15:56:25 -070045 get(ApplicationAdminService.class).install(stream);
46 return Response.ok().build();
Thomas Vachuska530e52a2015-05-06 19:51:32 -070047 }
48
Jian Li97d6b2d2016-01-20 10:13:43 -080049 @Path("{name}/icon")
50 @GET
51 @Produces("image/png")
52 public Response getIcon(@PathParam("name") String name) throws IOException {
53 ApplicationAdminService service = get(ApplicationAdminService.class);
54 ApplicationId appId = service.getId(name);
55 Application app = service.getApplication(appId);
56 return Response.ok(app.icon()).build();
57 }
Thomas Vachuska530e52a2015-05-06 19:51:32 -070058}