2 * Copyright 2017 ZTE Corporation.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.activiti.rest.conf.init;
19 import java.io.FileInputStream;
20 import java.io.FileNotFoundException;
21 import java.util.List;
23 import javax.annotation.PostConstruct;
25 import org.activiti.engine.RepositoryService;
26 import org.activiti.engine.repository.DeploymentBuilder;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.context.annotation.Configuration;
31 import org.springframework.core.env.Environment;
34 public class InitBaseProcessDefinition {
36 protected static final Logger LOGGER = LoggerFactory.getLogger(InitBaseProcessDefinition.class);
39 protected RepositoryService repositoryService;
42 protected Environment environment;
47 if (Boolean.valueOf(this.environment.getProperty("init.process.definitions", "true"))
49 LOGGER.info("Initializing base process definitions");
50 initBaseProcessDefinitions();
54 protected void initBaseProcessDefinitions() {
55 String deploymentName = "base definitions";
57 this.repositoryService.createDeploymentQuery().deploymentName(deploymentName).list();
59 if ((deploymentList == null) || (deploymentList.isEmpty())) {
61 String classPath = this.getClass().getClassLoader().getResource("/").getPath();
62 classPath = classPath.replaceAll("WEB-INF/classes", "baseProccessDefinition");
64 File files = new File(classPath);
65 DeploymentBuilder builder = this.repositoryService.createDeployment().name(deploymentName);
66 File flist[] = files.listFiles();
67 if (flist != null && flist.length != 0) {
68 for (File f : flist) {
70 String fileName = f.getName();
71 if (fileName != null && fileName.endsWith("bpmn20.xml")) {
73 builder.addInputStream(fileName, new FileInputStream(f));
74 LOGGER.info("deploy success: {}", fileName);
75 } catch (FileNotFoundException e) {
76 LOGGER.info("deploy failed: {}", fileName);