diff --git a/blade-service/blade-flow/pom.xml b/blade-service/blade-flow/pom.xml index 197bd3c3..3d791f04 100644 --- a/blade-service/blade-flow/pom.xml +++ b/blade-service/blade-flow/pom.xml @@ -50,22 +50,8 @@ org.flowable - flowable-ui-modeler-rest + flowable-json-converter ${flowable.version} - - - org.apache.logging.log4j - log4j-slf4j-impl - - - org.apache.logging.log4j - log4j-core - - - org.slf4j - jul-to-slf4j - - diff --git a/blade-service/blade-flow/src/main/java/org/springblade/flowable/FlowApplication.java b/blade-service/blade-flow/src/main/java/org/springblade/flowable/FlowApplication.java index 163509c7..cbb79dd2 100644 --- a/blade-service/blade-flow/src/main/java/org/springblade/flowable/FlowApplication.java +++ b/blade-service/blade-flow/src/main/java/org/springblade/flowable/FlowApplication.java @@ -16,20 +16,10 @@ */ package org.springblade.flowable; -import org.flowable.ui.common.conf.DevelopmentConfiguration; import org.springblade.core.cloud.feign.EnableBladeFeign; import org.springblade.core.launch.BladeApplication; import org.springblade.core.launch.constant.AppConstant; -import org.springblade.flowable.engine.constant.FlowableConstant; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration; -import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; -import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration; -import org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration; -import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; -import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.FilterType; +import org.springframework.cloud.client.SpringCloudApplication; /** * Flowable启动器 @@ -37,20 +27,7 @@ import org.springframework.context.annotation.FilterType; * @author Chill */ @EnableBladeFeign -@EnableDiscoveryClient -@EnableCircuitBreaker -@SpringBootApplication( - exclude = { - SecurityAutoConfiguration.class, - UserDetailsServiceAutoConfiguration.class, - LiquibaseAutoConfiguration.class, - MultipartAutoConfiguration.class - } -) -@ComponentScan( - basePackages = {AppConstant.BASE_PACKAGES, FlowableConstant.FLOWABLE_BASE_PACKAGES}, - excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {DevelopmentConfiguration.class}) -) +@SpringCloudApplication public class FlowApplication { public static void main(String[] args) { diff --git a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/config/FlowableConfiguration.java b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/config/FlowableConfiguration.java index 4460a672..fa453234 100644 --- a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/config/FlowableConfiguration.java +++ b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/config/FlowableConfiguration.java @@ -20,9 +20,7 @@ import lombok.AllArgsConstructor; import org.flowable.spring.SpringProcessEngineConfiguration; import org.flowable.spring.boot.EngineConfigurationConfigurer; import org.flowable.spring.boot.FlowableProperties; -import org.flowable.ui.modeler.properties.FlowableModelerAppProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** @@ -36,11 +34,6 @@ import org.springframework.context.annotation.Configuration; public class FlowableConfiguration implements EngineConfigurationConfigurer { private FlowableProperties flowableProperties; - @Bean - public FlowableModelerAppProperties flowableModelerAppProperties() { - return new FlowableModelerAppProperties(); - } - @Override public void configure(SpringProcessEngineConfiguration engineConfiguration) { engineConfiguration.setActivityFontName(flowableProperties.getActivityFontName()); diff --git a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/config/SecurityConfiguration.java b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/config/SecurityConfiguration.java deleted file mode 100644 index fde0ad00..00000000 --- a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/config/SecurityConfiguration.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.springblade.flowable.engine.config; - -import lombok.extern.slf4j.Slf4j; -import org.flowable.ui.common.properties.FlowableRestAppProperties; -import org.flowable.ui.common.security.ActuatorRequestMatcher; -import org.flowable.ui.common.security.DefaultPrivileges; -import org.flowable.ui.modeler.properties.FlowableModelerAppProperties; -import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest; -import org.springframework.boot.actuate.health.HealthEndpoint; -import org.springframework.boot.actuate.info.InfoEndpoint; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.annotation.Order; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.config.http.SessionCreationPolicy; - -/** - * SecurityConfiguration - * - * @author Chill - */ -@Slf4j -@Configuration -@EnableWebSecurity -public class SecurityConfiguration { - - @Configuration - @Order(1) - public static class ApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter { - - protected final FlowableRestAppProperties restAppProperties; - protected final FlowableModelerAppProperties modelerAppProperties; - - public ApiWebSecurityConfigurationAdapter(FlowableRestAppProperties restAppProperties, - FlowableModelerAppProperties modelerAppProperties) { - this.restAppProperties = restAppProperties; - this.modelerAppProperties = modelerAppProperties; - } - - @Override - protected void configure(HttpSecurity http) throws Exception { - - http - .sessionManagement() - .sessionCreationPolicy(SessionCreationPolicy.STATELESS) - .and() - .csrf() - .disable(); - - http.antMatcher("/**").authorizeRequests().antMatchers("/**").permitAll(); - - - } - } - - @ConditionalOnClass(EndpointRequest.class) - @Configuration - @Order(5) - public static class ActuatorWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter { - - @Override - protected void configure(HttpSecurity http) throws Exception { - - http - .sessionManagement() - .sessionCreationPolicy(SessionCreationPolicy.STATELESS) - .and() - .csrf() - .disable(); - - http - .requestMatcher(new ActuatorRequestMatcher()) - .authorizeRequests() - .requestMatchers(EndpointRequest.to(InfoEndpoint.class, HealthEndpoint.class)).authenticated() - .requestMatchers(EndpointRequest.toAnyEndpoint()).hasAnyAuthority(DefaultPrivileges.ACCESS_ADMIN) - .and().httpBasic(); - } - } -} diff --git a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/entity/FlowModel.java b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/entity/FlowModel.java index 167d4973..398f107b 100644 --- a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/entity/FlowModel.java +++ b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/entity/FlowModel.java @@ -33,6 +33,12 @@ public class FlowModel implements Serializable { private static final long serialVersionUID = 1L; + public static final int MODEL_TYPE_BPMN = 0; + public static final int MODEL_TYPE_FORM = 2; + public static final int MODEL_TYPE_APP = 3; + public static final int MODEL_TYPE_DECISION_TABLE = 4; + public static final int MODEL_TYPE_CMMN = 5; + private String id; private String name; private String modelKey; diff --git a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/mapper/FlowMapper.java b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/mapper/FlowMapper.java index 39e8e337..8e836f60 100644 --- a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/mapper/FlowMapper.java +++ b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/mapper/FlowMapper.java @@ -36,4 +36,11 @@ public interface FlowMapper extends BaseMapper { * @return */ List selectFlowPage(IPage page, FlowModel flowModel); + + /** + * 获取模型 + * @param parentModelId + * @return + */ + List findByParentModelId(String parentModelId); } diff --git a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/mapper/FlowMapper.xml b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/mapper/FlowMapper.xml index ed64df3a..fb332e62 100644 --- a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/mapper/FlowMapper.xml +++ b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/mapper/FlowMapper.xml @@ -44,4 +44,10 @@ a.created DESC + + diff --git a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/service/impl/FlowServiceImpl.java b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/service/impl/FlowServiceImpl.java index 3ac1d901..681cfbfe 100644 --- a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/service/impl/FlowServiceImpl.java +++ b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/service/impl/FlowServiceImpl.java @@ -18,13 +18,18 @@ package org.springblade.flowable.engine.service.impl; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.flowable.bpmn.converter.BpmnXMLConverter; +import org.flowable.bpmn.model.BpmnModel; +import org.flowable.bpmn.model.Process; +import org.flowable.editor.language.json.converter.BpmnJsonConverter; import org.flowable.engine.RepositoryService; import org.flowable.engine.repository.Deployment; import org.flowable.engine.repository.ProcessDefinition; -import org.flowable.ui.modeler.domain.Model; -import org.flowable.ui.modeler.serviceapi.ModelService; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.tool.utils.StringUtil; import org.springblade.flowable.engine.constant.FlowableConstant; @@ -34,7 +39,9 @@ import org.springblade.flowable.engine.service.FlowService; import org.springframework.stereotype.Service; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * 工作流服务实现类 @@ -46,8 +53,10 @@ import java.util.List; @AllArgsConstructor public class FlowServiceImpl extends ServiceImpl implements FlowService { + private static BpmnJsonConverter bpmnJsonConverter = new BpmnJsonConverter(); + private static BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter(); + private ObjectMapper objectMapper; private RepositoryService repositoryService; - private ModelService modelService; @Override public IPage selectFlowPage(IPage page, FlowModel flowModel) { @@ -56,8 +65,14 @@ public class FlowServiceImpl extends ServiceImpl implemen @Override public boolean deploy(String modelId, String category) { - Model model = modelService.getModel(modelId); - byte[] bytes = modelService.getBpmnXML(model); + + FlowModel model = this.getById(modelId); + + if (model == null) { + throw new ServiceException("No model found with the given id: " + modelId); + } + + byte[] bytes = getBpmnXML(model); String processName = model.getName(); if (!StringUtil.endsWithIgnoreCase(processName, FlowableConstant.suffix)) { @@ -67,7 +82,7 @@ public class FlowServiceImpl extends ServiceImpl implemen Deployment deployment = repositoryService.createDeployment() .addBytes(processName, bytes) .name(model.getName()) - .key(model.getKey()) + .key(model.getModelKey()) .deploy(); log.debug("流程部署--------deploy:" + deployment + " 分类---------->" + category); @@ -92,4 +107,72 @@ public class FlowServiceImpl extends ServiceImpl implemen return true; } } + + + private byte[] getBpmnXML(FlowModel model) { + BpmnModel bpmnModel = getBpmnModel(model); + return getBpmnXML(bpmnModel); + } + + + private byte[] getBpmnXML(BpmnModel bpmnModel) { + for (Process process : bpmnModel.getProcesses()) { + if (StringUtils.isNotEmpty(process.getId())) { + char firstCharacter = process.getId().charAt(0); + // no digit is allowed as first character + if (Character.isDigit(firstCharacter)) { + process.setId("a" + process.getId()); + } + } + } + return bpmnXMLConverter.convertToXML(bpmnModel); + } + + private BpmnModel getBpmnModel(FlowModel model) { + BpmnModel bpmnModel = null; + try { + Map formMap = new HashMap<>(16); + Map decisionTableMap = new HashMap<>(16); + + List referencedModels = baseMapper.findByParentModelId(model.getId()); + for (FlowModel childModel : referencedModels) { + if (FlowModel.MODEL_TYPE_FORM == childModel.getModelType()) { + formMap.put(childModel.getId(), childModel); + + } else if (FlowModel.MODEL_TYPE_DECISION_TABLE == childModel.getModelType()) { + decisionTableMap.put(childModel.getId(), childModel); + } + } + + bpmnModel = getBpmnModel(model, formMap, decisionTableMap); + + } catch (Exception e) { + log.error("Could not generate BPMN 2.0 model for {}", model.getId(), e); + throw new ServiceException("Could not generate BPMN 2.0 model"); + } + + return bpmnModel; + } + + private BpmnModel getBpmnModel(FlowModel model, Map formMap, Map decisionTableMap) { + try { + ObjectNode editorJsonNode = (ObjectNode) objectMapper.readTree(model.getModelEditorJson()); + Map formKeyMap = new HashMap<>(16); + for (FlowModel formModel : formMap.values()) { + formKeyMap.put(formModel.getId(), formModel.getModelKey()); + } + + Map decisionTableKeyMap = new HashMap<>(16); + for (FlowModel decisionTableModel : decisionTableMap.values()) { + decisionTableKeyMap.put(decisionTableModel.getId(), decisionTableModel.getModelKey()); + } + + return bpmnJsonConverter.convertToBpmnModel(editorJsonNode, formKeyMap, decisionTableKeyMap); + + } catch (Exception e) { + log.error("Could not generate BPMN 2.0 model for {}", model.getId(), e); + throw new ServiceException("Could not generate BPMN 2.0 model"); + } + } + } diff --git a/blade-service/blade-flow/src/main/resources/application.yml b/blade-service/blade-flow/src/main/resources/application.yml index 4fb24594..bbdac577 100644 --- a/blade-service/blade-flow/src/main/resources/application.yml +++ b/blade-service/blade-flow/src/main/resources/application.yml @@ -3,9 +3,3 @@ flowable: label-font-name: \u5B8B\u4F53 annotation-font-name: \u5B8B\u4F53 check-process-definitions: false - common: - app: - idm-url: http://localhost:9999 - idm-admin: - user: admin - password: test