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() == falsereturn 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, intmaxHeight) {

    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;

    }

  }

 

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值