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.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 
  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 
  26 public class Bpmn4Tosca2Bpmn {
\r 
  28     private static Logger log = LoggerFactory.getLogger(Bpmn4Tosca2Bpmn.class);
\r 
  31      * Transforms the given BPMN4Tosca Json management into a bpmn plan that can
\r 
  32      * be excuted by activiti.
\r 
  35      * @param srcBpmn4ToscaJsonFile
\r 
  36      * @param targetBpmnArchive
\r 
  37      * @throws Exception 
\r 
  39     public void transform(String processId, URI srcBpmn4ToscaJsonFile, URI targetBpmnArchive) throws Exception {
\r 
  40         log.info("transform start");
\r 
  42         // parse json object
\r 
  43         Bpmn4ToscaJsonParser parser = new Bpmn4ToscaJsonParser();
\r 
  44         Process process = parser.parse(processId, srcBpmn4ToscaJsonFile);
\r 
  46         // transform bpmn template
\r 
  47         BpmnPlanArtefactWriter writer = new BpmnPlanArtefactWriter(process);
\r 
  48         String workflowString = writer.completePlanTemplate();
\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