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
10 * ZTE - initial API and implementation and/or initial documentation
\r
12 package org.onap.sdc.workflowdesigner.converter;
\r
14 import java.io.IOException;
\r
15 import java.net.URI;
\r
16 import java.nio.file.Files;
\r
17 import java.nio.file.Path;
\r
18 import java.nio.file.Paths;
\r
19 import java.nio.file.StandardOpenOption;
\r
21 import org.onap.sdc.workflowdesigner.model.Process;
\r
22 import org.onap.sdc.workflowdesigner.parser.Bpmn4ToscaJsonParser;
\r
23 import org.onap.sdc.workflowdesigner.writer.BpmnPlanArtefactWriter;
\r
24 import org.slf4j.Logger;
\r
25 import org.slf4j.LoggerFactory;
\r
27 public class Bpmn4Tosca2Bpmn {
\r
29 private static Logger log = LoggerFactory.getLogger(Bpmn4Tosca2Bpmn.class);
\r
32 * Transforms the given BPMN4Tosca Json management into a bpmn plan that can
\r
33 * be excuted by activiti.
\r
36 * @param srcBpmn4ToscaJsonFile
\r
37 * @param targetBpmnArchive
\r
38 * @throws Exception
\r
40 public void transform(String processId, URI srcBpmn4ToscaJsonFile, URI targetBpmnArchive) throws Exception {
\r
41 log.info("transform start");
\r
43 // parse json object
\r
44 Bpmn4ToscaJsonParser parser = new Bpmn4ToscaJsonParser();
\r
45 Process process = parser.parse(processId, srcBpmn4ToscaJsonFile);
\r
47 // transform bpmn template
\r
48 BpmnPlanArtefactWriter writer = new BpmnPlanArtefactWriter(process);
\r
49 String workflowString = writer.completePlanTemplate();
\r
51 // write bpmn to file
\r
52 writeStringToFile(workflowString, Paths.get(targetBpmnArchive));
\r
53 log.info("transform end");
\r
56 public static Path writeStringToFile(String content, Path targetPath) throws IOException {
\r
57 return Files.write(targetPath, content.getBytes(), StandardOpenOption.CREATE);
\r