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
10 * ZTE - initial API and implementation and/or initial documentation
13 package org.onap.sdc.workflowdesigner.resources;
15 import java.io.IOException;
17 import javax.ws.rs.Consumes;
18 import javax.ws.rs.GET;
19 import javax.ws.rs.PUT;
20 import javax.ws.rs.Path;
21 import javax.ws.rs.PathParam;
22 import javax.ws.rs.Produces;
23 import javax.ws.rs.core.MediaType;
24 import javax.ws.rs.core.Response;
26 import org.eclipse.jetty.http.HttpStatus;
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;
32 import com.codahale.metrics.annotation.Timed;
34 import io.swagger.annotations.Api;
35 import io.swagger.annotations.ApiOperation;
36 import io.swagger.annotations.ApiParam;
37 import io.swagger.annotations.ApiResponse;
38 import io.swagger.annotations.ApiResponses;
41 * Workflow Modeler Resource.
45 @Api(tags = {"Workflow Modeler"})
46 public class WorkflowModelerResource {
47 private static final Logger logger = LoggerFactory.getLogger(WorkflowModelerResource.class);
56 @Consumes(MediaType.APPLICATION_JSON)
57 @Produces(MediaType.APPLICATION_JSON)
58 @ApiOperation(value = "Get Model", response = String.class)
59 @ApiResponses(value = {
60 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
61 response = String.class),
62 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
63 message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
64 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "server internal error",
65 response = String.class)})
67 public Response getModel(@ApiParam(value = "id") @PathParam("id") String id) {
68 String filePath = "model.json";
70 String json = FileCommonUtils.readString(filePath);
71 return Response.status(Response.Status.OK).entity(json).build();
72 } catch (IOException e) {
73 logger.error("getServiceTemplateById failed.", e);
74 throw RestUtils.newInternalServerErrorException(e);
80 @Consumes(MediaType.APPLICATION_JSON)
81 @Produces(MediaType.APPLICATION_JSON)
82 @ApiOperation(value = "Save Model", response = String.class)
83 @ApiResponses(value = {
84 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
85 response = String.class),
86 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
87 message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
88 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "server internal error",
89 response = String.class)})
91 public Response saveModel(@ApiParam(value = "id") @PathParam("id") String id,
92 @ApiParam(value = "Model Content", required = true) String json) {
93 String filePath = "model.json";
95 FileCommonUtils.write(filePath, json);
96 return Response.status(Response.Status.OK).entity(json).build();
97 } catch (IOException e) {
98 logger.error("getServiceTemplateById failed.", e);
99 throw RestUtils.newInternalServerErrorException(e);