예제 #1
0
  private void manageAttachments(KpeopleAction action, DataHandler stream) throws IOException {

    InputStream is = null;
    String hashcode = null;
    try {
      is = stream.getInputStream();
      hashcode = Hashcode.getHashcode(is, Hashcode.SHA512);
    } catch (IOException e) {
      e.printStackTrace();
      throw e;
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
    }

    String path = (String) currentProperties.get(KpeopleLabel.getEventXMLPath());
    try {
      path = ActionDataProcessorUtil.checkEventXMLPath(path);
    } catch (Exception e1) {
      e1.printStackTrace();
    }

    FileOutputStream outputStream = null;
    File tmpFilePath = null;
    try {
      path = path + action.getIdAction() + "-" + fileName;
      tmpFilePath = new File(path);
      outputStream = new FileOutputStream(tmpFilePath);
      stream.writeTo(outputStream);

      outputStream.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    // ActionDataProcessorUtil.deleteEventFile(tmpFilePath);

    String idAttachmentId = Long.toString(action.getIdAction()) + "-" + hashcode.substring(0, 6);

    KpeopleAttachment attachment = new KpeopleAttachment();
    attachment.setAttachmentName(fileName);
    attachment.setAttachmentHashcode(hashcode);
    attachment.setAttachmentData(path);
    attachment.setIdAttachment(idAttachmentId);
    attachment.setAttachmentType(eventResult.getContentType());

    eventResult.addAttachment(attachment);
  }