0b4f2edbb38f072de13b0b6bc3004f6853e207bd
[sdc/sdc-workflow-designer.git] /
1 /**\r
2  * Copyright (c) 2017 ZTE Corporation.\r
3  * All rights reserved. This program and the accompanying materials\r
4  * are made available under the Apache License, Version 2.0\r
5  * and the Eclipse Public License v1.0 which both accompany this distribution,\r
6  * and are available at http://www.eclipse.org/legal/epl-v10.html\r
7  * and http://www.apache.org/licenses/LICENSE-2.0\r
8  *\r
9  * Contributors:\r
10  *     ZTE - initial API and implementation and/or initial documentation\r
11  */\r
12 package org.onap.sdc.workflowdesigner.converter;\r
13 \r
14 import java.net.URI;\r
15 import java.nio.file.Files;\r
16 import java.nio.file.Path;\r
17 import java.nio.file.Paths;\r
18 import java.nio.file.StandardOpenOption;\r
19 \r
20 import org.onap.sdc.workflowdesigner.model.Process;\r
21 import org.onap.sdc.workflowdesigner.parser.Bpmn4ToscaJsonParser;\r
22 import org.onap.sdc.workflowdesigner.writer.BpmnPlanArtefactWriter;\r
23 import org.slf4j.Logger;\r
24 import org.slf4j.LoggerFactory;\r
25 \r
26 public class Bpmn4Tosca2Bpmn {\r
27 \r
28     private static Logger log = LoggerFactory.getLogger(Bpmn4Tosca2Bpmn.class);\r
29 \r
30     /**\r
31      * Transforms the given BPMN4Tosca Json management into a bpmn plan that can\r
32      * be excuted by activiti.\r
33      * <p>\r
34      *\r
35      * @param srcBpmn4ToscaJsonFile\r
36      * @param targetBpmnArchive\r
37      * @throws Exception \r
38      */\r
39     public void transform(String processId, URI srcBpmn4ToscaJsonFile, URI targetBpmnArchive) throws Exception {\r
40         log.info("transform start");\r
41 \r
42         // parse json object\r
43         Bpmn4ToscaJsonParser parser = new Bpmn4ToscaJsonParser();\r
44         Process process = parser.parse(processId, srcBpmn4ToscaJsonFile);\r
45 \r
46         // transform bpmn template\r
47         BpmnPlanArtefactWriter writer = new BpmnPlanArtefactWriter(process);\r
48         String workflowString = writer.completePlanTemplate();\r
49 \r
50         // write bpmn to file\r
51         Path targetPath = Paths.get(targetBpmnArchive);\r
52         Files.write(targetPath, workflowString.getBytes(), StandardOpenOption.CREATE);\r
53         log.info("transform end");\r
54     }\r
55 \r
56 }\r