83babfa240a6e233d7ef62ba84b38f7020ffe4cc
[vnfsdk/refrepo.git] /
1 /**
2  * Copyright 2017 Huawei Technologies Co., Ltd.
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 package org.onap.vnfsdk.marketplace.resource;
17
18 import java.io.InputStream;
19
20 import javax.servlet.http.HttpServletRequest;
21 import javax.ws.rs.Consumes;
22 import javax.ws.rs.DELETE;
23 import javax.ws.rs.GET;
24 import javax.ws.rs.POST;
25 import javax.ws.rs.Path;
26 import javax.ws.rs.PathParam;
27 import javax.ws.rs.Produces;
28 import javax.ws.rs.QueryParam;
29 import javax.ws.rs.core.Context;
30 import javax.ws.rs.core.HttpHeaders;
31 import javax.ws.rs.core.MediaType;
32 import javax.ws.rs.core.Response;
33
34 import org.eclipse.jetty.http.HttpStatus;
35 import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
36 import org.glassfish.jersey.media.multipart.FormDataParam;
37 import org.onap.vnfsdk.marketplace.entity.response.CsarFileUriResponse;
38 import org.onap.vnfsdk.marketplace.entity.response.PackageMeta;
39 import org.onap.vnfsdk.marketplace.entity.response.UploadPackageResponse;
40 import org.onap.vnfsdk.marketplace.onboarding.entity.OnBoardingResult;
41 import org.onap.vnfsdk.marketplace.wrapper.PackageWrapper;
42
43 import io.swagger.annotations.Api;
44 import io.swagger.annotations.ApiOperation;
45 import io.swagger.annotations.ApiParam;
46 import io.swagger.annotations.ApiResponse;
47 import io.swagger.annotations.ApiResponses;
48
49 /**
50  * csar package service.
51  * 
52  * @author 10189609
53  * 
54  */
55 @Path("/PackageResource")
56 @Api(tags = {"Package Resource"})
57 public class PackageResource {
58
59     @Path("/updatestatus")
60     @POST
61     @ApiOperation(value = "update validate and lifecycle test status", response = UploadPackageResponse.class)
62     @Consumes(MediaType.APPLICATION_JSON)
63     @Produces(MediaType.APPLICATION_JSON)
64     @ApiResponses(value = {
65             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
66                     response = String.class),
67             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
68                     message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
69             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "update  error",
70                     response = String.class)})
71     public Response updateValidateStatus(
72             @ApiParam(value = "http request body") @Context HttpServletRequest request,
73             @ApiParam(value = "http header") @Context HttpHeaders head
74     ) throws Exception {
75         InputStream input = request.getInputStream();
76         return PackageWrapper.getInstance().updateValidateStatus(input, head);
77
78     }
79
80
81     @Path("/csars")
82     @GET
83     @ApiOperation(value = "get csar package list by condition", response = PackageMeta.class,
84     responseContainer = "List")
85     @Produces(MediaType.APPLICATION_JSON)
86     @ApiResponses(value = {
87             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
88                     response = String.class),
89             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
90             message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
91             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error",
92             response = String.class)})
93     public Response queryPackageListByCond(
94             @ApiParam(value = "csar name") @QueryParam("name") String name, @ApiParam(
95                     value = "csar provider") @QueryParam("provider") String provider, @ApiParam(
96                             value = "csar version") @QueryParam("version") String version, @ApiParam(
97                                     value = "delay to delete") @QueryParam("deletionPending") String deletionPending,
98             @ApiParam(value = "csar type") @QueryParam("type") String type) {
99         return PackageWrapper.getInstance().queryPackageListByCond(name, provider, version,
100                 deletionPending, type);
101     }
102
103     @Path("/csars/{csarId}")
104     @GET
105     @ApiOperation(value = "get csar package list", response = PackageMeta.class,
106     responseContainer = "List")
107     @Produces(MediaType.APPLICATION_JSON)
108     @ApiResponses(value = {
109             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
110                     response = String.class),
111             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
112             message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
113             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error",
114             response = String.class)})
115     public Response queryPackageById(
116             @ApiParam(value = "csar id") @PathParam("csarId") String csarId) {
117         return PackageWrapper.getInstance().queryPackageById(csarId);
118     }
119     @Path("/csars")
120     @POST
121     @ApiOperation(value = "upload csar package", response = UploadPackageResponse.class)
122     @Consumes(MediaType.MULTIPART_FORM_DATA)
123     @Produces(MediaType.APPLICATION_JSON)
124     @ApiResponses(value = {
125             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
126                     response = String.class),
127             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
128             message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
129             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error",
130             response = String.class)})
131     public Response uploadPackage(
132             @ApiParam(value = "file inputstream",
133             required = true) @FormDataParam("file") InputStream uploadedInputStream,@FormDataParam("params") String details,
134             @ApiParam(value = "file detail",
135             required = false) @FormDataParam("file") FormDataContentDisposition fileDetail,
136             @ApiParam(value = "http header") @Context HttpHeaders head) throws Exception {
137         return PackageWrapper.getInstance().uploadPackage(uploadedInputStream, fileDetail, details, head);
138     }
139
140     @Path("/csars/{csarId}")
141     @DELETE
142     @ApiOperation(value = "delete a package")
143     @ApiResponses(value = {
144             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
145                     response = String.class),
146             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
147             message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
148             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error",
149             response = String.class)})
150     public Response delPackage(@ApiParam(value = "csar Id") @PathParam("csarId") String csarId) {
151         return PackageWrapper.getInstance().delPackage(csarId);
152     }
153
154     @Path("/csars/{csarId}/files")
155     @GET
156     @ApiOperation(value = "get csar file uri by csarId", response = CsarFileUriResponse.class)
157     @Produces(MediaType.APPLICATION_JSON)
158     @ApiResponses(value = {
159             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
160                     response = String.class),
161             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
162             message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
163             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error",
164             response = String.class)})
165     public Response getCsarFileUri(
166             @ApiParam(value = "csar Id", required = true) @PathParam("csarId") String csarId) {
167         return PackageWrapper.getInstance().getCsarFileUri(csarId);
168     }
169
170     @Path("/csars/{csarId}/downloaded")
171     @GET
172     @ApiOperation(value = "update download count for a package",response = Response.class)
173     public Response updateDwonloadCount(@ApiParam(value = "csar Id") @PathParam("csarId") String csarId) {
174         return PackageWrapper.getInstance().updateDwonloadCount(csarId);
175     }
176
177     @Path("/csars/{csarId}/reupload")
178     @POST
179     @ApiOperation(value = "re-upload csar package", response = UploadPackageResponse.class)
180     @Consumes(MediaType.MULTIPART_FORM_DATA)
181     @Produces(MediaType.APPLICATION_JSON)
182     @ApiResponses(value = {
183             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
184                     response = String.class),
185             @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
186             message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
187             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error",
188             response = String.class)})
189     public Response reUploadPackage(
190             @ApiParam(value = "csar Id") @PathParam("csarId") String csarId,
191             @ApiParam(value = "file inputstream",
192             required = true) @FormDataParam("file") InputStream uploadedInputStream,@FormDataParam("params") String details,
193             @ApiParam(value = "file detail",
194             required = false) @FormDataParam("file") FormDataContentDisposition fileDetail,
195             @ApiParam(value = "http header") @Context HttpHeaders head) throws Exception {
196         return PackageWrapper.getInstance().reUploadPackage(csarId,uploadedInputStream, fileDetail, details, head);
197     } 
198
199     @Path("/csars/{csarId}/onboardstatus")
200     @GET
201     @ApiOperation(value="Get VNF OnBoarding Result", response=OnBoardingResult.class)
202     @Produces(MediaType.APPLICATION_JSON)
203     public Response getOnBoardingResult(@ApiParam("csar Id") @PathParam("csarId") String csarId, 
204             @ApiParam("operation type") @QueryParam("operTypeId") String operTypeId, 
205             @ApiParam("operation id") @QueryParam("operId") String operId)
206     {
207         return PackageWrapper.getInstance().getOnBoardingResult(csarId, operTypeId, operId);
208     }
209
210     @Path("/csars/{csarId}/operresult")
211     @GET
212     @ApiOperation(value = "Get VNF OnBoarded Opeartion Result", response = Response.class)
213     @Produces(MediaType.APPLICATION_JSON)
214     public Response getOperStatus(@ApiParam(value = "csar Id") @PathParam("csarId") String csarId,
215             @ApiParam(value = "operation type") @QueryParam("operTypeId") String operTypeId) {
216         return PackageWrapper.getInstance().getOperResultByOperTypeId(csarId,operTypeId);
217     }
218
219     @Path("/csars/onboardsteps")
220     @GET
221     @ApiOperation(value="Get VNF OnBoarded Steps", response=Response.class)
222     @Produces(MediaType.APPLICATION_JSON)
223     public Response getOnBoardingSteps()
224     {
225         return PackageWrapper.getInstance().getOnBoardingSteps();
226     }
227 }