The online editor can be directly referenced, Spring MVC integration activiti-explorer 5.22 (1) Steps 2, 3, and 4 in, and Spring MVC integration activiti-explorer 5.22 (2) The configuration and basic integration of spring boot are basically completed. Let's recap what needs to be modified in spring boot
1. Modify ModelSaveRestResource.java class
import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; import org.activiti.editor.constants.ModelDataJsonConstants; import org.activiti.engine.ActivitiException; import org.activiti.engine.RepositoryService; import org.activiti.engine.repository.Model; import org.apache.batik.transcoder.TranscoderInput; import org.apache.batik.transcoder.TranscoderOutput; import org.apache.batik.transcoder.image.PNGTranscoder; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; @RestController @RequestMapping(value = "/service") public class ModelSaveRestResource implements ModelDataJsonConstants { private static final Logger LOGGER = LogManager.getLogger(ModelSaveRestResource.class); @Autowired private RepositoryService repositoryService; @Autowired private ObjectMapper objectMapper; @RequestMapping(value = "/model/{modelId}/save", method = RequestMethod.PUT) @ResponseStatus(value = HttpStatus.OK) public void saveModel(@PathVariable String modelId, @RequestParam("name") String name, @RequestParam("json_xml") String json_xml, @RequestParam("svg_xml") String svg_xml, @RequestParam("description") String description) { try { Model model = repositoryService.getModel(modelId); ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo()); modelJson.put(MODEL_NAME, name); modelJson.put(MODEL_DESCRIPTION, description); model.setMetaInfo(modelJson.toString()); model.setName(name); repositoryService.saveModel(model); repositoryService.addModelEditorSource(model.getId(),json_xml.getBytes("utf-8")); InputStream svgStream = new ByteArrayInputStream(svg_xml.getBytes("utf-8")); TranscoderInput input = new TranscoderInput(svgStream); PNGTranscoder transcoder = new PNGTranscoder(); // Setup output ByteArrayOutputStream outStream = new ByteArrayOutputStream(); TranscoderOutput output = new TranscoderOutput(outStream); // Do the transformation transcoder.transcode(input, output); final byte[] result = outStream.toByteArray(); repositoryService.addModelEditorSourceExtra(model.getId(), result); outStream.close(); } catch (Exception e) { LOGGER.error("Error saving model", e); throw new ActivitiException("Error saving model", e); } } }
2. Modify the acquisition location of the stencilset.json file
Since all static files in Springboot are placed in resources/static, you need to modify the location of obtaining files in StencilsetRestResource.java, as follows
InputStream stencilsetStream = getClass().getClassLoader().getResourceAsStream("static/activiti/stencilset.json");
3. Solve the problem of Chinese code storage of flow chart
Just create a new configuration class of customactiviticconfig.java. The code is as follows
import org.activiti.spring.SpringProcessEngineConfiguration; import org.activiti.spring.boot.ProcessEngineConfigurationConfigurer; import org.springframework.stereotype.Component; @Component public class CustomActivitiConfig implements ProcessEngineConfigurationConfigurer { /** * Overriding * <h5>Function: set the Chinese font in the flow chart to prevent the flow chart from displaying disorderly code < / H5 > * @param processEngineConfiguration */ @Override public void configure(SpringProcessEngineConfiguration processEngineConfiguration) { processEngineConfiguration.setActivityFontName("Song style"); processEngineConfiguration.setLabelFontName("Song style"); processEngineConfiguration.setAnnotationFontName("Song style"); } }
So far, the integration is over