2 * Copyright (c) 2017 ZTE Corporation.
\r
3 * All rights reserved. This program and the accompanying materials
\r
4 * are made available under the terms of the Eclipse Public License v1.0
\r
5 * and the Apache License 2.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.writer;
\r
14 import java.io.StringWriter;
\r
16 import org.apache.velocity.Template;
\r
17 import org.apache.velocity.VelocityContext;
\r
18 import org.apache.velocity.app.Velocity;
\r
19 import org.apache.velocity.app.VelocityEngine;
\r
20 import org.apache.velocity.exception.ParseErrorException;
\r
21 import org.apache.velocity.exception.ResourceNotFoundException;
\r
22 import org.onap.sdc.workflowdesigner.config.Config;
\r
23 import org.onap.sdc.workflowdesigner.model.Process;
\r
24 import org.slf4j.Logger;
\r
25 import org.slf4j.LoggerFactory;
\r
27 public class BpmnPlanArtefactWriter {
\r
29 private Process process;
\r
31 public static String TEMPLATE_PATH = Config.PROPERTIES.getProperty(Config.TEMPLATE_PATH);
\r
33 private static Logger log = LoggerFactory.getLogger(BpmnPlanArtefactWriter.class);
\r
35 public BpmnPlanArtefactWriter(Process process) throws Exception {
\r
36 this.process = process;
\r
40 public String completePlanTemplate() throws ResourceNotFoundException, ParseErrorException, Exception {
\r
41 log.debug("Completing BPMN process template...");
\r
43 VelocityContext context = new VelocityContext();
\r
45 VelocityEngine ve = new VelocityEngine();
\r
46 ve.setProperty("resource.loader", "class");
\r
47 ve.setProperty("class.resource.loader.class",
\r
48 "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
\r
49 Template planTemplate = ve.getTemplate(TEMPLATE_PATH + "bpmn_template.xml");
\r
51 context.put("process", process);
\r
52 context.put("templatePath", TEMPLATE_PATH);
\r
53 StringWriter planWriter = new StringWriter();
\r
54 planTemplate.merge(context, planWriter);
\r
56 String bpmnProcessContent = planWriter.toString();
\r
58 log.debug("Completed BPMN process template" + bpmnProcessContent);
\r
60 return bpmnProcessContent;
\r