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;
16 import java.io.StringBufferInputStream;
18 import javax.ws.rs.Consumes;
19 import javax.ws.rs.GET;
20 import javax.ws.rs.PUT;
21 import javax.ws.rs.Path;
22 import javax.ws.rs.PathParam;
23 import javax.ws.rs.Produces;
24 import javax.ws.rs.core.MediaType;
25 import javax.ws.rs.core.Response;
27 import org.eclipse.jetty.http.HttpStatus;
28 import org.onap.sdc.workflowdesigner.utils.FileCommonUtils;
29 import org.onap.sdc.workflowdesigner.utils.RestUtils;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 import com.codahale.metrics.annotation.Timed;
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;
42 * Workflow Modeler Resource.
46 @Api(tags = {"Workflow Modeler"})
47 public class WorkflowModelerResource {
48 private static final Logger logger = LoggerFactory.getLogger(WorkflowModelerResource.class);
57 @Consumes(MediaType.APPLICATION_JSON)
58 @Produces(MediaType.APPLICATION_JSON)
59 @ApiOperation(value = "Get Model", response = String.class)
60 @ApiResponses(value = {
61 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
62 response = String.class),
63 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
64 message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
65 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "server internal error",
66 response = String.class)})
68 public Response getModel(@ApiParam(value = "id") @PathParam("id") String id) {
69 String filePath = "model.json";
71 String json = FileCommonUtils.readString(filePath);
72 return Response.status(Response.Status.OK).entity(json).build();
73 } catch (IOException e) {
74 logger.error("getServiceTemplateById failed.", e);
75 throw RestUtils.newInternalServerErrorException(e);
81 @Consumes(MediaType.APPLICATION_JSON)
82 @Produces(MediaType.APPLICATION_JSON)
83 @ApiOperation(value = "Save Model", response = String.class)
84 @ApiResponses(value = {
85 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
86 response = String.class),
87 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
88 message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
89 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "server internal error",
90 response = String.class)})
92 public Response saveModel(@ApiParam(value = "id") @PathParam("id") String id,
93 @ApiParam(value = "Model Content", required = true) String json) {
94 String filePath = "model.json";
96 FileCommonUtils.saveFile(new StringBufferInputStream(json), "", filePath);
97 return Response.status(Response.Status.OK).entity(id).build();
98 } catch (IOException e) {
99 logger.error("getServiceTemplateById failed.", e);
100 throw RestUtils.newInternalServerErrorException(e);