protected void addResource(
      Object source,
      Map<String, byte[]> resourceMap,
      String resourceRootPath,
      String resourceName) {

    String resourcePath = (resourceRootPath == null ? "" : resourceRootPath).concat(resourceName);

    log.log(Level.FINEST, "discovered process resource {0}", resourcePath);

    InputStream inputStream = null;

    try {
      if (source instanceof File) {
        try {
          inputStream = new FileInputStream((File) source);
        } catch (IOException e) {
          throw new ProcessEngineException(
              "Could not open file for reading " + source + ". " + e.getMessage(), e);
        }
      } else {
        inputStream = (InputStream) source;
      }
      byte[] bytes = IoUtil.readInputStream(inputStream, resourcePath);

      resourceMap.put(resourcePath, bytes);

    } finally {
      if (inputStream != null) {
        IoUtil.closeSilently(inputStream);
      }
    }
  }
  public Attachment execute(CommandContext commandContext) {
    AttachmentEntity attachment = new AttachmentEntity();
    attachment.setName(attachmentName);
    attachment.setDescription(attachmentDescription);
    attachment.setType(attachmentType);
    attachment.setTaskId(taskId);
    attachment.setProcessInstanceId(processInstanceId);
    attachment.setUrl(url);

    DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
    dbSqlSession.insert(attachment);

    if (content != null) {
      byte[] bytes = IoUtil.readInputStream(content, attachmentName);
      ByteArrayEntity byteArray = new ByteArrayEntity(bytes);
      dbSqlSession.insert(byteArray);
      attachment.setContentId(byteArray.getId());
    }

    CommentManager commentManager = commandContext.getCommentManager();
    if (commentManager.isHistoryEnabled()) {
      String userId = Authentication.getAuthenticatedUserId();
      CommentEntity comment = new CommentEntity();
      comment.setUserId(userId);
      comment.setType(CommentEntity.TYPE_EVENT);
      comment.setTime(ClockUtil.getCurrentTime());
      comment.setTaskId(taskId);
      comment.setProcessInstanceId(processInstanceId);
      comment.setAction(Event.ACTION_ADD_ATTACHMENT);
      comment.setMessage(attachmentName);
      commentManager.insert(comment);
    }

    return attachment;
  }
  @Deployment(resources = {"org/camunda/bpm/engine/test/repository/one.cmmn"})
  public void testGetCaseModel() throws Exception {
    CaseDefinitionQuery query = repositoryService.createCaseDefinitionQuery();

    CaseDefinition caseDefinition = query.singleResult();
    String caseDefinitionId = caseDefinition.getId();

    InputStream caseModel = repositoryService.getCaseModel(caseDefinitionId);

    assertNotNull(caseModel);

    byte[] readInputStream = IoUtil.readInputStream(caseModel, "caseModel");
    String model = new String(readInputStream, "UTF-8");

    assertTrue(model.contains("<case id=\"one\" name=\"One\">"));

    IoUtil.closeSilently(caseModel);
  }
Пример #4
0
 public static void writeStringToFile(String content, String filePath) {
   BufferedOutputStream outputStream = null;
   try {
     outputStream = new BufferedOutputStream(new FileOutputStream(getFile(filePath)));
     outputStream.write(content.getBytes());
     outputStream.flush();
   } catch (Exception e) {
     throw new ProcessEngineException("Couldn't write file " + filePath, e);
   } finally {
     IoUtil.closeSilently(outputStream);
   }
 }
Пример #5
0
 public static String readFileAsString(String filePath) {
   byte[] buffer = new byte[(int) getFile(filePath).length()];
   BufferedInputStream inputStream = null;
   try {
     inputStream = new BufferedInputStream(new FileInputStream(getFile(filePath)));
     inputStream.read(buffer);
   } catch (Exception e) {
     throw new ProcessEngineException("Couldn't read file " + filePath + ": " + e.getMessage());
   } finally {
     IoUtil.closeSilently(inputStream);
   }
   return new String(buffer, Charset.forName("UTF-8"));
 }