From 3694205db52ef2b3db5a869ae9e6c3568e616bad Mon Sep 17 00:00:00 2001 From: Lvbo163 Date: Tue, 26 Sep 2017 15:03:13 +0800 Subject: Write data to workflow template Issue-ID: SDC-398 Change-Id: Ia5cec2af1f9f2018b42933d48628a42fbefb29b5 Signed-off-by: Lvbo163 --- sdc-workflow-designer-server/pom.xml | 6 ++ .../writer/BpmnPlanArtefactWriter.java | 64 ++++++++++++++++++++++ .../resources/bpmn-templates/bpmn_template.xml | 12 ++++ 3 files changed, 82 insertions(+) create mode 100644 sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/writer/BpmnPlanArtefactWriter.java create mode 100644 sdc-workflow-designer-server/src/main/resources/bpmn-templates/bpmn_template.xml diff --git a/sdc-workflow-designer-server/pom.xml b/sdc-workflow-designer-server/pom.xml index d28ff81b..3ba7f3b9 100644 --- a/sdc-workflow-designer-server/pom.xml +++ b/sdc-workflow-designer-server/pom.xml @@ -28,6 +28,7 @@ 1.7.25 2.9.1 + 1.6.2 @@ -45,5 +46,10 @@ jackson-databind ${jackson.version} + + org.apache.velocity + velocity + ${velocity.version} + diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/writer/BpmnPlanArtefactWriter.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/writer/BpmnPlanArtefactWriter.java new file mode 100644 index 00000000..c39b0bba --- /dev/null +++ b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/writer/BpmnPlanArtefactWriter.java @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2017 ZTE Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * ZTE - initial API and implementation and/or initial documentation + */ +package org.onap.sdc.workflowdesigner.writer; + +import java.io.StringWriter; + +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.Velocity; +import org.apache.velocity.app.VelocityEngine; +import org.apache.velocity.exception.ParseErrorException; +import org.apache.velocity.exception.ResourceNotFoundException; +import org.onap.sdc.workflowdesigner.config.Config; +import org.onap.sdc.workflowdesigner.model.Process; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class BpmnPlanArtefactWriter { + + private Process process; + + public static String TEMPLATE_PATH = Config.PROPERTIES.getProperty(Config.TEMPLATE_PATH); + + private static Logger log = LoggerFactory.getLogger(BpmnPlanArtefactWriter.class); + + public BpmnPlanArtefactWriter(Process process) throws Exception { + this.process = process; + Velocity.init(); + } + + public String completePlanTemplate() throws ResourceNotFoundException, ParseErrorException, Exception { + log.debug("Completing BPMN process template..."); + + VelocityContext context = new VelocityContext(); + + VelocityEngine ve = new VelocityEngine(); + ve.setProperty("resource.loader", "class"); + ve.setProperty("class.resource.loader.class", + "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); + Template planTemplate = ve.getTemplate(TEMPLATE_PATH + "bpmn_template.xml"); + + context.put("process", process); + context.put("templatePath", TEMPLATE_PATH); + StringWriter planWriter = new StringWriter(); + planTemplate.merge(context, planWriter); + + String bpmnProcessContent = planWriter.toString(); + + log.debug("Completed BPMN process template" + bpmnProcessContent); + + return bpmnProcessContent; + + } + +} diff --git a/sdc-workflow-designer-server/src/main/resources/bpmn-templates/bpmn_template.xml b/sdc-workflow-designer-server/src/main/resources/bpmn-templates/bpmn_template.xml new file mode 100644 index 00000000..7783ece8 --- /dev/null +++ b/sdc-workflow-designer-server/src/main/resources/bpmn-templates/bpmn_template.xml @@ -0,0 +1,12 @@ + + + + + + + -- cgit 1.2.3-korg