implement class for the Rest APIs. 13/30213/1
authorYuanHu <yuan.hu1@zte.com.cn>
Mon, 5 Feb 2018 07:03:34 +0000 (15:03 +0800)
committerYuanHu <yuan.hu1@zte.com.cn>
Mon, 5 Feb 2018 07:05:17 +0000 (15:05 +0800)
Provide implement Service Resource Classes for the Rest APIs.

Issue-ID: SDC-997

Change-Id: If94f3835e69e12455380fa10513118a6e11575c5
Signed-off-by: YuanHu <yuan.hu1@zte.com.cn>
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/WorkflowDesignerApp.java
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/ExtendActivityResource.java [new file with mode: 0644]
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/WorkflowModelerResource.java [new file with mode: 0644]

index 002da23..da40796 100644 (file)
@@ -13,8 +13,8 @@
 package org.onap.sdc.workflowdesigner;
 
 import org.glassfish.jersey.media.multipart.MultiPartFeature;
-// import org.onap.sdc.workflowdesigner.resources.ExtendActivityResource;
-// import org.onap.sdc.workflowdesigner.resources.WorkflowModelerResource;
+import org.onap.sdc.workflowdesigner.resources.ExtendActivityResource;
+import org.onap.sdc.workflowdesigner.resources.WorkflowModelerResource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -50,8 +50,8 @@ public class WorkflowDesignerApp extends Application<WorkflowDesignerConfigurati
   public void run(WorkflowDesignerConfiguration configuration, Environment environment) {
     LOGGER.info("Start to initialize Workflow Designer.");
 
-    // environment.jersey().register(new WorkflowModelerResource());
-    // environment.jersey().register(new ExtendActivityResource());
+    environment.jersey().register(new WorkflowModelerResource());
+    environment.jersey().register(new ExtendActivityResource());
 
     // register rest interface
     environment.jersey().packages("org.onap.sdc.workflowdesigner.resources");
diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/ExtendActivityResource.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/ExtendActivityResource.java
new file mode 100644 (file)
index 0000000..35d77a0
--- /dev/null
@@ -0,0 +1,101 @@
+/**
+ * Copyright (c) 2017 ZTE Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the Apache License, Version 2.0
+ * and the Eclipse Public License v1.0 which both accompany this distribution,
+ * and are available at http://www.eclipse.org/legal/epl-v10.html
+ * and http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Contributors:
+ *     ZTE - initial API and implementation and/or initial documentation
+ */
+
+package org.onap.sdc.workflowdesigner.resources;
+
+import java.io.IOException;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.eclipse.jetty.http.HttpStatus;
+import org.onap.sdc.workflowdesigner.utils.FileCommonUtils;
+import org.onap.sdc.workflowdesigner.utils.RestUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.codahale.metrics.annotation.Timed;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+
+/**
+ * Extend Activity Resource.
+ * 
+ */
+@Path("/ext-activities")
+@Api(tags = {"Workflow Modeler"})
+public class ExtendActivityResource {
+  private static final Logger logger = LoggerFactory.getLogger(ExtendActivityResource.class);
+
+  /**
+   * test function.
+   * 
+   * @return Response
+   */
+  @Path("/")
+  @GET
+  @Consumes(MediaType.APPLICATION_JSON)
+  @Produces(MediaType.APPLICATION_JSON)
+  @ApiOperation(value = "Get Model", response = String.class)
+  @ApiResponses(value = {
+      @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
+          response = String.class),
+      @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
+          message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
+      @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "server internal error",
+          response = String.class)})
+  @Timed
+  public Response getExtActivities(@ApiParam(value = "sence") @QueryParam("sence") String sence) {
+    String filePath = "ext-activities.json";
+    try {
+      String json = FileCommonUtils.readString(filePath);
+      return Response.status(Response.Status.OK).entity(json).build();
+    } catch (IOException e) {
+      logger.error("getServiceTemplateById failed.", e);
+      throw RestUtils.newInternalServerErrorException(e);
+    }
+  }
+
+  @Path("/displayInfo")
+  @GET
+  @Consumes(MediaType.APPLICATION_JSON)
+  @Produces(MediaType.APPLICATION_JSON)
+  @ApiOperation(value = "Get Model", response = String.class)
+  @ApiResponses(value = {
+      @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
+          response = String.class),
+      @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
+          message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
+      @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "server internal error",
+          response = String.class)})
+  @Timed
+  public Response getDisplayInfo(@ApiParam(value = "sence") @QueryParam("sence") String sence) {
+    String filePath = "ext-activities-display-info.json";
+    try {
+      String json = FileCommonUtils.readString(filePath);
+      return Response.status(Response.Status.OK).entity(json).build();
+    } catch (IOException e) {
+      logger.error("getServiceTemplateById failed.", e);
+      throw RestUtils.newInternalServerErrorException(e);
+    }
+  }
+
+}
diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/WorkflowModelerResource.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/WorkflowModelerResource.java
new file mode 100644 (file)
index 0000000..8b3d723
--- /dev/null
@@ -0,0 +1,104 @@
+/**
+ * Copyright (c) 2017 ZTE Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the Apache License, Version 2.0
+ * and the Eclipse Public License v1.0 which both accompany this distribution,
+ * and are available at http://www.eclipse.org/legal/epl-v10.html
+ * and http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Contributors:
+ *     ZTE - initial API and implementation and/or initial documentation
+ */
+
+package org.onap.sdc.workflowdesigner.resources;
+
+import java.io.IOException;
+import java.io.StringBufferInputStream;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.eclipse.jetty.http.HttpStatus;
+import org.onap.sdc.workflowdesigner.utils.FileCommonUtils;
+import org.onap.sdc.workflowdesigner.utils.RestUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.codahale.metrics.annotation.Timed;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+
+/**
+ * Workflow Modeler Resource.
+ * 
+ */
+@Path("/models")
+@Api(tags = {"Workflow Modeler"})
+public class WorkflowModelerResource {
+  private static final Logger logger = LoggerFactory.getLogger(WorkflowModelerResource.class);
+
+  /**
+   * test function.
+   * 
+   * @return Response
+   */
+  @Path("/{id}")
+  @GET
+  @Consumes(MediaType.APPLICATION_JSON)
+  @Produces(MediaType.APPLICATION_JSON)
+  @ApiOperation(value = "Get Model", response = String.class)
+  @ApiResponses(value = {
+      @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
+          response = String.class),
+      @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
+          message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
+      @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "server internal error",
+          response = String.class)})
+  @Timed
+  public Response getModel(@ApiParam(value = "id") @PathParam("id") String id) {
+    String filePath = "model.json";
+    try {
+      String json = FileCommonUtils.readString(filePath);
+      return Response.status(Response.Status.OK).entity(json).build();
+    } catch (IOException e) {
+      logger.error("getServiceTemplateById failed.", e);
+      throw RestUtils.newInternalServerErrorException(e);
+    }
+  }
+
+  @Path("/{id}")
+  @PUT
+  @Consumes(MediaType.APPLICATION_JSON)
+  @Produces(MediaType.APPLICATION_JSON)
+  @ApiOperation(value = "Save Model", response = String.class)
+  @ApiResponses(value = {
+      @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
+          response = String.class),
+      @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
+          message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
+      @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "server internal error",
+          response = String.class)})
+  @Timed
+  public Response saveModel(@ApiParam(value = "id") @PathParam("id") String id,
+      @ApiParam(value = "Model Content", required = true) String json) {
+    String filePath = "model.json";
+    try {
+      FileCommonUtils.saveFile(new StringBufferInputStream(json), "", filePath);
+      return Response.status(Response.Status.OK).entity(id).build();
+    } catch (IOException e) {
+      logger.error("getServiceTemplateById failed.", e);
+      throw RestUtils.newInternalServerErrorException(e);
+    }
+  }
+
+}