47e56d1a001fac85759ee4eba5891a1d2b5f1392
[sdc/sdc-workflow-designer.git] /
1 /**
2  * Copyright (c) 2017-2018 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.resources.entity.ExtendActivity;
27 import org.onap.sdc.workflowdesigner.utils.FileCommonUtils;
28 import org.onap.sdc.workflowdesigner.utils.RestUtils;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 import com.codahale.metrics.annotation.Timed;
33 import com.google.gson.Gson;
34
35 import io.swagger.annotations.Api;
36 import io.swagger.annotations.ApiOperation;
37 import io.swagger.annotations.ApiParam;
38 import io.swagger.annotations.ApiResponse;
39 import io.swagger.annotations.ApiResponses;
40
41 /**
42  * Extend Activity Resource.
43  * 
44  */
45 @Path("/ext-activities")
46 @Api(tags = {"Workflow Modeler"})
47 public class ExtendActivityResource {
48   private static final Logger LOGGER = LoggerFactory.getLogger(ExtendActivityResource.class);
49
50   private static final String EXT_ACTIVITIES_FILE_NAME = "..\\distribution\\src\\main\\assembly\\ext-activities.json";
51
52   /**
53    * test function.
54    * 
55    * @return Response
56    */
57   @Path("/")
58   @GET
59   @Consumes(MediaType.APPLICATION_JSON)
60   @Produces(MediaType.APPLICATION_JSON)
61   @ApiOperation(value = "Get Model", response = ExtendActivity.class, responseContainer = "List")
62   @ApiResponses(value = {
63       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
64           response = String.class),
65       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
66           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
67       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "server internal error",
68           response = String.class)})
69   @Timed
70   public Response getExtActivities(@ApiParam(value = "sence") @QueryParam("sence") String sence) {
71
72     try {
73       String json = FileCommonUtils.readString(EXT_ACTIVITIES_FILE_NAME);
74       
75       Gson gson = new Gson();
76       ExtendActivity[] extActivities = gson.fromJson(json, ExtendActivity[].class);
77       return Response.status(Response.Status.OK).entity(extActivities).build();
78     } catch (IOException e) {
79       LOGGER.error("getServiceTemplateById failed.", e);
80       throw RestUtils.newInternalServerErrorException(e);
81     }
82
83   }
84
85   @Path("/displayInfo")
86   @GET
87   @Consumes(MediaType.APPLICATION_JSON)
88   @Produces(MediaType.APPLICATION_JSON)
89   @ApiOperation(value = "Get Model", response = String.class)
90   @ApiResponses(value = {
91       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
92           response = String.class),
93       @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
94           message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
95       @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "server internal error",
96           response = String.class)})
97   @Timed
98   public Response getDisplayInfo(@ApiParam(value = "sence") @QueryParam("sence") String sence) {
99     String filePath = "ext-activities-display-info.json";
100     try {
101       String json = FileCommonUtils.readString(filePath);
102       return Response.status(Response.Status.OK).entity(json).build();
103     } catch (IOException e) {
104       LOGGER.error("getServiceTemplateById failed.", e);
105       throw RestUtils.newInternalServerErrorException(e);
106     }
107   }
108
109 }