35d77a0116aeb10c5b163a795bf91b8d8a7d0711
[sdc/sdc-workflow-designer.git] /
1 /**
2  * Copyright (c) 2017 ZTE Corporation.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the Apache License, Version 2.0
5  * and the Eclipse Public License v1.0 which both accompany this distribution,
6  * and are available at http://www.eclipse.org/legal/epl-v10.html
7  * and http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Contributors:
10  *     ZTE - initial API and implementation and/or initial documentation
11  */
12
13 package org.onap.sdc.workflowdesigner.resources;
14
15 import java.io.IOException;
16
17 import javax.ws.rs.Consumes;
18 import javax.ws.rs.GET;
19 import javax.ws.rs.Path;
20 import javax.ws.rs.Produces;
21 import javax.ws.rs.QueryParam;
22 import javax.ws.rs.core.MediaType;
23 import javax.ws.rs.core.Response;
24
25 import org.eclipse.jetty.http.HttpStatus;
26 import org.onap.sdc.workflowdesigner.utils.FileCommonUtils;
27 import org.onap.sdc.workflowdesigner.utils.RestUtils;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 import com.codahale.metrics.annotation.Timed;
32
33 import io.swagger.annotations.Api;
34 import io.swagger.annotations.ApiOperation;
35 import io.swagger.annotations.ApiParam;
36 import io.swagger.annotations.ApiResponse;
37 import io.swagger.annotations.ApiResponses;
38
39 /**
40  * Extend Activity Resource.
41  * 
42  */
43 @Path("/ext-activities")
44 @Api(tags = {"Workflow Modeler"})
45 public class ExtendActivityResource {
46   private static final Logger logger = LoggerFactory.getLogger(ExtendActivityResource.class);
47
48   /**
49    * test function.
50    * 
51    * @return Response
52    */
53   @Path("/")
54   @GET
55   @Consumes(MediaType.APPLICATION_JSON)
56   @Produces(MediaType.APPLICATION_JSON)
57   @ApiOperation(value = "Get Model", response = String.class)
58   @ApiResponses(value = {
59       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
60           response = String.class),
61       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
62           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
63       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "server internal error",
64           response = String.class)})
65   @Timed
66   public Response getExtActivities(@ApiParam(value = "sence") @QueryParam("sence") String sence) {
67     String filePath = "ext-activities.json";
68     try {
69       String json = FileCommonUtils.readString(filePath);
70       return Response.status(Response.Status.OK).entity(json).build();
71     } catch (IOException e) {
72       logger.error("getServiceTemplateById failed.", e);
73       throw RestUtils.newInternalServerErrorException(e);
74     }
75   }
76
77   @Path("/displayInfo")
78   @GET
79   @Consumes(MediaType.APPLICATION_JSON)
80   @Produces(MediaType.APPLICATION_JSON)
81   @ApiOperation(value = "Get Model", response = String.class)
82   @ApiResponses(value = {
83       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
84           response = String.class),
85       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
86           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
87       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "server internal error",
88           response = String.class)})
89   @Timed
90   public Response getDisplayInfo(@ApiParam(value = "sence") @QueryParam("sence") String sence) {
91     String filePath = "ext-activities-display-info.json";
92     try {
93       String json = FileCommonUtils.readString(filePath);
94       return Response.status(Response.Status.OK).entity(json).build();
95     } catch (IOException e) {
96       logger.error("getServiceTemplateById failed.", e);
97       throw RestUtils.newInternalServerErrorException(e);
98     }
99   }
100
101 }