Parsing extend activities from file. 73/36873/2
authorYuanHu <yuan.hu1@zte.com.cn>
Tue, 20 Mar 2018 00:57:44 +0000 (08:57 +0800)
committerYuanHu <yuan.hu1@zte.com.cn>
Tue, 20 Mar 2018 01:27:11 +0000 (09:27 +0800)
Parsing extend activities from json file.

Issue-ID: SDC-1129

Change-Id: Ideb7c473d17c2d533676fcc44bdefba183d34a9f
Signed-off-by: YuanHu <yuan.hu1@zte.com.cn>
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/ExtendActivityResource.java

index 35d77a0..47e56d1 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2017 ZTE Corporation.
+ * Copyright (c) 2017-2018 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,
@@ -23,12 +23,14 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
 import org.eclipse.jetty.http.HttpStatus;
+import org.onap.sdc.workflowdesigner.resources.entity.ExtendActivity;
 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 com.google.gson.Gson;
 
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -43,7 +45,9 @@ import io.swagger.annotations.ApiResponses;
 @Path("/ext-activities")
 @Api(tags = {"Workflow Modeler"})
 public class ExtendActivityResource {
-  private static final Logger logger = LoggerFactory.getLogger(ExtendActivityResource.class);
+  private static final Logger LOGGER = LoggerFactory.getLogger(ExtendActivityResource.class);
+
+  private static final String EXT_ACTIVITIES_FILE_NAME = "..\\distribution\\src\\main\\assembly\\ext-activities.json";
 
   /**
    * test function.
@@ -54,7 +58,7 @@ public class ExtendActivityResource {
   @GET
   @Consumes(MediaType.APPLICATION_JSON)
   @Produces(MediaType.APPLICATION_JSON)
-  @ApiOperation(value = "Get Model", response = String.class)
+  @ApiOperation(value = "Get Model", response = ExtendActivity.class, responseContainer = "List")
   @ApiResponses(value = {
       @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
           response = String.class),
@@ -64,14 +68,18 @@ public class ExtendActivityResource {
           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();
+      String json = FileCommonUtils.readString(EXT_ACTIVITIES_FILE_NAME);
+      
+      Gson gson = new Gson();
+      ExtendActivity[] extActivities = gson.fromJson(json, ExtendActivity[].class);
+      return Response.status(Response.Status.OK).entity(extActivities).build();
     } catch (IOException e) {
-      logger.error("getServiceTemplateById failed.", e);
+      LOGGER.error("getServiceTemplateById failed.", e);
       throw RestUtils.newInternalServerErrorException(e);
     }
+
   }
 
   @Path("/displayInfo")
@@ -93,7 +101,7 @@ public class ExtendActivityResource {
       String json = FileCommonUtils.readString(filePath);
       return Response.status(Response.Status.OK).entity(json).build();
     } catch (IOException e) {
-      logger.error("getServiceTemplateById failed.", e);
+      LOGGER.error("getServiceTemplateById failed.", e);
       throw RestUtils.newInternalServerErrorException(e);
     }
   }