• Activiti工作流资源的获取和存储实现


      前两天同事问我,工作流activiti通过activiti-probe部署时候上传的工作流配置文件到存在哪里。我当时懵了,当时知道在数据库存储工作流资源文件的信息。但是不知道文件系统是否存有。于是,研究一下源代码明白,资源信息存储和获取的结构如下:

     在工作流Activiti中流程xml文件和流程图片的存储和实现:

    在工作流部署的时候需要上传相关的工作流文件到相关的项目中。其中如果是文件采用方式如下,将图片和或者文件转换为二进制字节流存储。
    存储的表结构如下:
    create table ACT_GE_BYTEARRAY (

        ID_ varchar(64) not null,

        REV_ integer,

        NAME_ varchar(255),

        DEPLOYMENT_ID_ varchar(64),

        BYTES_ BLOB,

        primary key (ID_)

    );

    其中NAME_存储文件名称。
        BYTES_
    存储流程资源文件。
    代码实现如下:
    package org.activiti.engine.identity;

     

    import java.io.ByteArrayInputStream;

    import java.io.InputStream;

     

     

    /**

     * @author Tom Baeyens

     */

    public class Picture {

     

     protected byte[] bytes;

     protected String mimeType;

     

     public Picture(byte[] bytes, String mimeType) {

        this.bytes = bytes;

        this.mimeType = mimeType;

     }

     

     public byte[] getBytes() {

        return bytes;

     }

     

     public InputStream getInputStream() {

       return new ByteArrayInputStream(bytes);

     }

     

     public String getMimeType() {

        return mimeType;

     }

    }

    package org.activiti.rest.api.identity;

     

    import org.activiti.engine.ActivitiException;

    import org.activiti.engine.identity.Picture;

    import org.activiti.rest.api.ActivitiUtil;

    import org.activiti.rest.api.SecuredResource;

    import org.restlet.data.CacheDirective;

    import org.restlet.data.MediaType;

    import org.restlet.representation.InputRepresentation;

    import org.restlet.resource.Get;

     

    /**

     * @author Tijs Rademakers

     */

    public class UserPictureResource extends SecuredResource {

     

     @Get

     public InputRepresentation getPicture() {

        if(authenticate() == false) return null;

       

        String userId = (String) getRequest().getAttributes().get("userId");

        if(userId == null) {

          throw new ActivitiException("No userId provided");

        }

        Picture picture = ActivitiUtil.getIdentityService().getUserPicture(userId);

       

        String contentType = picture.getMimeType();

        MediaType mediatType = MediaType.IMAGE_PNG;

        if(contentType != null) {

          if(contentType.contains(";")) {

            contentType = contentType.substring(0, contentType.indexOf(";"));

          }

          mediatType = MediaType.valueOf(contentType);

        }

        InputRepresentation output = new InputRepresentation(picture.getInputStream(), mediatType);

        getResponse().getCacheDirectives().add(CacheDirective.maxAge(28800));

       

        return output;

     }

     

    }

    package org.activiti.explorer.util;

     

    import java.awt.image.BufferedImage;

     

     

    /**

     * @author Joram Barrez

     */

    public class ImageUtil {

     

     protected static final Logger LOGGER = Logger.getLogger(ImageUtil.class.getName());

     

     /**

       * Resizes the given image (passed as {@link InputStream}.

       * If the image is smaller then the given maximum width or height, the image

       * will be proportionally resized.

       */

     public static InputStream smallify(InputStream imageInputStream, String mimeType, int maxWidth, int maxHeight) {

        try {

          BufferedImage image = ImageIO.read(imageInputStream);

         

          int width = Math.min(image.getWidth(), maxWidth);

          int height = Math.min(image.getHeight(), maxHeight);

         

          Mode mode = Mode.AUTOMATIC;

          if (image.getHeight() > maxHeight) {

            mode = Mode.FIT_TO_HEIGHT;

          }

         

          if (width != image.getWidth() || height != image.getHeight()) {

            image = Scalr.resize(image, mode, width, height);

          }

         

          ByteArrayOutputStream bos = new ByteArrayOutputStream();

          ImageIO.write(image, Constants.MIMETYPE_EXTENSION_MAPPING.get(mimeType), bos);

          return new ByteArrayInputStream(bos.toByteArray());

        } catch (IOException e) {

          LOGGER.log(Level.SEVERE, "Exception while resizing image", e);

          return null;

        }

     }

     

    }
  • 相关阅读:
    Ocelot简易教程(二)之快速开始1
    Ocelot简易教程(一)之Ocelot是什么
    InfluxDB学习之InfluxDB的基本操作
    InfluxDB入门教程
    .NET Core微服务之基于App.Metrics+InfluxDB+Grafana实现统一性能监控
    .net Core 微服务
    IdentityServer4 接口说明
    WINDOWS命令行关闭本地占用的端口
    并发负载压力测试
    C#操作Mongodb
  • 原文地址:https://www.cnblogs.com/shihao/p/2323704.html
Copyright © 2020-2023  润新知