Sava Workflow Artifact to SDC 09/37309/1
authorYuanHu <yuan.hu1@zte.com.cn>
Wed, 21 Mar 2018 02:06:57 +0000 (10:06 +0800)
committerYuanHu <yuan.hu1@zte.com.cn>
Wed, 21 Mar 2018 02:06:57 +0000 (10:06 +0800)
Sava Workflow Artifact to SDC

Issue-ID: SDC-1004

Change-Id: Ifab77db0d3b739304c0eff283aef3d382f6bf4bb
Signed-off-by: YuanHu <yuan.hu1@zte.com.cn>
distribution/src/main/assembly/temp_workflow.json [moved from distribution/src/main/assembly/model.json with 100% similarity]
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/externalservice/sdc/entity/WorkflowArtifactInfo.java
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/WorkflowModelerResource.java

index 23c8f86..e2cab05 100644 (file)
@@ -28,19 +28,11 @@ public class WorkflowArtifactInfo implements Serializable {
   
   private String payloadData;
   
-
-  /**
-   * @param artifactName
-   * @param description
-   * @param artifactType
-   * @param payloadData
-   */
-  public WorkflowArtifactInfo(String artifactName, String description, String artifactType,
+  public WorkflowArtifactInfo(String artifactName, String description,
       String payloadData) {
     super();
     this.artifactName = artifactName;
     this.description = description;
-    this.artifactType = artifactType;
     this.payloadData = payloadData;
   }
 
index 317d59d..f6f1699 100644 (file)
@@ -27,9 +27,14 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
 import org.eclipse.jetty.http.HttpStatus;
+import org.onap.sdc.workflowdesigner.common.WorkflowDesignerException;
+import org.onap.sdc.workflowdesigner.externalservice.sdc.SDCServiceProxy;
+import org.onap.sdc.workflowdesigner.externalservice.sdc.entity.WorkflowArtifactInfo;
 import org.onap.sdc.workflowdesigner.model.Process;
 import org.onap.sdc.workflowdesigner.parser.Bpmn4ToscaJsonParser;
+import org.onap.sdc.workflowdesigner.resources.entity.WorkflowInfo;
 import org.onap.sdc.workflowdesigner.utils.FileCommonUtils;
+import org.onap.sdc.workflowdesigner.utils.JsonUtils;
 import org.onap.sdc.workflowdesigner.utils.RestUtils;
 import org.onap.sdc.workflowdesigner.writer.BpmnPlanArtefactWriter;
 import org.slf4j.Logger;
@@ -51,7 +56,7 @@ import io.swagger.annotations.ApiResponses;
 @Api(tags = {"Workflow Modeler"})
 public class WorkflowModelerResource {
   private static final Logger logger = LoggerFactory.getLogger(WorkflowModelerResource.class);
-  
+
   private static final String WORKFLOW_JSON_TEMP_FILE_NAME = "temp_workflow.json";
   private static final String WORKFLOW_XML_TEMP_FILE_NAME = "temp_workflow.xml";
 
@@ -83,8 +88,8 @@ public class WorkflowModelerResource {
     }
   }
 
-  
-  
+
+
   @Path("/{id}")
   @PUT
   @Consumes(MediaType.APPLICATION_JSON)
@@ -107,8 +112,9 @@ public class WorkflowModelerResource {
       String processName = "plan_" + UUID.randomUUID().toString();
       String bpmn = buildBPMN(srcUri, processName);
 
+      save2SDC(json, bpmn);
       FileCommonUtils.write(WORKFLOW_XML_TEMP_FILE_NAME, bpmn);
-      
+
       return Response.status(Response.Status.OK).entity(json).build();
     } catch (IOException e) {
       logger.error("save workflow failed.", e);
@@ -119,6 +125,23 @@ public class WorkflowModelerResource {
     }
   }
 
+
+
+  /**
+   * @param json
+   * @param bpmn
+   * @throws WorkflowDesignerException
+   */
+  private void save2SDC(String json, String bpmn) throws WorkflowDesignerException {
+    WorkflowInfo workflowInfo = JsonUtils.fromJson(json, WorkflowInfo.class);
+    WorkflowArtifactInfo workflowArtifactInfo =
+        new WorkflowArtifactInfo(workflowInfo.getName(), workflowInfo.getDescription(), bpmn);
+
+    SDCServiceProxy sdcProxy = new SDCServiceProxy();
+    sdcProxy.saveWorkflowArtifact(workflowInfo.getUuid(), workflowInfo.getOperationId(),
+        workflowInfo.getId(), workflowArtifactInfo);
+  }
+
   /**
    * 
    * @param srcUri
@@ -130,7 +153,7 @@ public class WorkflowModelerResource {
   private String buildBPMN(URI srcUri, String processName) throws IOException, Exception {
     Bpmn4ToscaJsonParser parser = new Bpmn4ToscaJsonParser();
     Process process = parser.parse(processName, srcUri);
-    
+
     // transform bpmn template
     BpmnPlanArtefactWriter writer = new BpmnPlanArtefactWriter(process);
     return writer.completePlanTemplate();